springboot 整合mybatis 项目的启动中出现了一个问题
Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
看到这提示就知道是依赖注入时出错了,就是这个 @Autowired注解
@Autowired
private ITUserService userService;
出现这个@Autowired注解错误主要就是这几个原因
- ITUserService 没有实现类、找不到实现类
- ITUserService 的实现类中没有使用@Service 注解标记 spring找不到
- 还有就是没有配置扫描路径
而我的这是springboot 不需要配置路径,实现类也肯定是有的。
最后排查发现是少了配置扫描mybatis的mapper路径
因为service依赖mapper导致是提示 ITUserService错误
解决
在springboot的启动的Application类中添加@MapperScan注解
@SpringBootApplication
@MapperScan("com.dgdaoze.DaoZeConsumeUp.*.mapper")
public class DaoZeConsumeUpApplication {
public static void main(String[] args) {
SpringApplication.run(DaoZeConsumeUpApplication.class, args);
}
}