解决org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'c

解决org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'c_第1张图片

添加注解@Autowired显红,但是代码没有报错,原因可能是没有注入依赖.

运行后的报错信息如下:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.lzy.weixinsell.service.impl.ProductServiceImplTest': Unsatisfied dependency expressed through field 'productService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.lzy.weixinsell.service.impl.ProductServiceImpl' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]


解决方法

需要在类ProductServiceImpl添加@Service

 

你可能感兴趣的:(解决org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'c)