出错问题:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'XXXXX': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: XXXXXXX; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [XXXXXX] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1120)
原因是在autowire时,找不到相应的类,上述问题是因为XXXXX的实现类中没有加相应的注解。如dao层 @Repository 如service层 @Service
解决方法:
出现上述问题的原因是没有在相应的实现类中追加相应的注解。
1、本人发现的问题是在Service层的实现类中没有追加:
@Service(“XXXXX”)
在service的实现类XXXXXServiceImpl.java的开始,追加@Service(“XXXXX”),如下:
@Service(“XXXXX”)
public class XXXXXServiceImpl implements XXXXXService{
……
}
2、追加完之后,把代码刷新并clean一下,重新启动tomcat,一般都会成功。