项目中还在使用SpringMVC框架进行开发,接到一个需求要把mysql数据库改为使用postgresql。
修改Tomcat中的server.xml中的数据库连接池后,发现并不能正常启动,抛出
Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘XXXXService’: Injection of autowired dependencies failed; nested exception is (省略一堆没用的信息)… expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
总之是提示XXXDao没有注入。
明显问题不是这个,切数据库前还是好的。
查了注解是否正确,连接池是否正确,发现问题不在这里。
最后找到问题在配置文件中。
ApplicationContext.xml中配置了
context:component-scan base-package
我们的配置里面,实现了一个过滤器,把全部crud请求过滤,只留下mysql的请求。
于是改之。
重启正常,问题解决。
心得:注解使用@Resource或者@Autowired都是一样的,不要在这上面纠结,问题大概率不在这里。