【SpringBoot】springboot启动报错The injection point has the following annotations: - @org.springframework.
项目场景:
在一次springboot项目启动时,控制台出现下面提示
***************************
APPLICATION FAILED TO START
***************************
Description:
Field icbc in com.yundaotu.hebi.service.AppImpl required a bean of type ‘com.itfuture.service.userService’ 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 ‘com.itfuture.service.UserService’ in your configuration.
问题描述
出现上面情况,我们肯定会觉得是UserService没有交给spring管理,所以spring容器找不到userService这个bean真的是这样吗?
下面是我的UserService的部分代码:
/**
* @author: wxh
* @version:v1.0
* @date: 2022/11/10 11:35
*/
@Service
public class UserServiceImpl implements UserService {
@Resource
private UserDao userDao;
}
那么,加了@Service,就是说UserService已经交给了spring管理,那为什么还是扫不到呢??
原因分析:
那么这里就要想想springMVC了,哦!对,springboot并不知道去哪找注解,也就是说得告诉springboot去扫描哪些包的注解!!
我的启动器:
@SpringBootApplication
public class EApplication {
public static void main(String[] args) {
SpringApplication.run(EApplication.class, args);
}
}
解决方案:
给启动器添加@ComponentScan(basePackages = { “com.itfuture.mapper” })
@SpringBootApplication
@MapperScan("com.itfuture.mapper")
public class EApplication {
public static void main(String[] args) {
SpringApplication.run(EApplication.class, args);
}
}
还没有评论,来说两句吧...