SpringBoot Mybatis注入异常
2017-02-24 09:59
423 查看
这几天在研究Spring Boot框架,早Spring Boot和Mybaits结合的时候,我在Action层面住入Service的代码没有报错,但是在Service注入Mybatis的Mapper接口的时候,报了如下的错误。
UserMapper的接口没有实现类,然后我就看了 我的Spring与Mybatis的Jar包也引入了,配置也配置了,怎么会报这样的错误。
解决方法:
后来发现Spring Boot的main启动方法,默认扫描的是当前包下的子包类,而我的base项目和test项目包的路径不对,当我修改包路径后,
Spring Boot就可以自动扫描到配置文件,Mapper同时也注入了。
java.lang.Object.wait(Native Method) java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143) com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43) [ERROR] 09:51:11 o.s.boot.SpringApplication => Application startup failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'iUserService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.company.test.dao.UserMapper com.company.test.service.impl.UserServiceImpl.userMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.company.test.dao.UserMapper] 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:334) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) at com.company.test.Application.main(Application.java:19) Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.company.test.dao.UserMapper com.company.test.service.impl.UserServiceImpl.userMapper; nested exception is org.springframework.beans.factory .NoSuchBeanDefinitionException: No qualifying bean of type [com.company.test.dao.UserMapper] found for dependency: expected at least 1 bean which qualifie s as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject (AutowiredAnnotationBeanPostProcessor.java:573) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues (AutowiredAnnotationBeanPostProcessor.java:331)错误提示
UserMapper的接口没有实现类,然后我就看了 我的Spring与Mybatis的Jar包也引入了,配置也配置了,怎么会报这样的错误。
解决方法:
后来发现Spring Boot的main启动方法,默认扫描的是当前包下的子包类,而我的base项目和test项目包的路径不对,当我修改包路径后,
Spring Boot就可以自动扫描到配置文件,Mapper同时也注入了。
相关文章推荐
- springboot与mybatis整合dao层不能注入的问题
- SpringCloud SpringBoot mybatis 分布式微服务(六)Spring Boot中Web应用的统一异常处理
- SpringBoot+Mybatis整合报,service注入失败,dao注入失败,
- springboot整合mybatis和pageHelper异常问题记录
- Spring Cloud Spring Boot mybatis分布式微服务云架构(十一)Web应用的统一异常处理
- Spring Cloud Spring Boot mybatis分布式微服务云架构(十一)Web应用的统一异常处理
- springboot 集成mybatis Invalid bound statement (not found)异常
- SpringBoot整合Mybatis无法注入dao
- 解决Spring boot使用Quartz时Job中无法注入Bean 空指针异常问题
- springboot整合mybatis mapper注入时显示could not autowire的解决
- Spring Cloud Spring Boot mybatis分布式微服务云架构(十一)Web应用的统一异常处理
- SpringCloud SpringBoot mybatis 分布式微服务(十九)springboot在启动时注入了哪些bean
- springboot Environment注入异常
- spring boot + mybatis BindingException异常解决
- springboot 集成mybatis Invalid bound statement (not found)异常
- Mybatis-Spring-注入映射器
- Mybatis-Spring-注入映射器
- Spring AOP操作action时无法注入,报NullPointer异常
- Mybatis MapperScannerConfigurer 自动扫描 将Mapper接口生成代理注入到Spring - 大新博客 - 推酷 - 360安全浏览器 7.1
- Mybatis-Spring-注入映射器