【SpringBoot】springboot启动报错The injection point has the following annotations: - @org.springframework.

ゞ 浴缸里的玫瑰 2023-09-29 17:36 90阅读 0赞

项目场景:

在一次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的部分代码:

  1. /**
  2. * @author: wxh
  3. * @version:v1.0
  4. * @date: 2022/11/10 11:35
  5. */
  6. @Service
  7. public class UserServiceImpl implements UserService {
  8. @Resource
  9. private UserDao userDao;
  10. }

那么,加了@Service,就是说UserService已经交给了spring管理,那为什么还是扫不到呢??


原因分析:

那么这里就要想想springMVC了,哦!对,springboot并不知道去哪找注解,也就是说得告诉springboot去扫描哪些包的注解!!

我的启动器:

  1. @SpringBootApplication
  2. public class EApplication {
  3. public static void main(String[] args) {
  4. SpringApplication.run(EApplication.class, args);
  5. }
  6. }

解决方案:

给启动器添加@ComponentScan(basePackages = { “com.itfuture.mapper” })

  1. @SpringBootApplication
  2. @MapperScan("com.itfuture.mapper")
  3. public class EApplication {
  4. public static void main(String[] args) {
  5. SpringApplication.run(EApplication.class, args);
  6. }
  7. }

发表评论

表情:
评论列表 (有 0 条评论,90人围观)

还没有评论,来说两句吧...

相关阅读