springboot找不到对象(自动注入失败)
今天在idea重新建立个springboot项目时,遇到这个奇怪的问题,说是找不到对应的bean,我猜想是@Mapper的问题
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-04-08 14:11:11.359 ERROR 7300 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field dao in cn.niit.controller.DemoController required a bean of type 'cn.niit.TestMapper.TestMapper' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'cn.niit.TestMapper.TestMapper' in your configuration.
Process finished with exit code 1
最后在网上查找后发现
pom.xml中的依赖,我导的是mybatis,而正确的依赖应该是导入mybatis-spring-boot-starter这个依赖
注意:
@Mapper这个注解引入的都是import org.apache.ibatis.annotations.Mapper;
最后在pom.xml加上mybatis-spring-boot-starter这个依赖就不报错了
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>