问题描述
Description:
Field authorService in com.luck.graduate.controller.AuthorController required a bean of type 'com.luck.graduate.service.AuthorService' 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.luck.graduate.service.AuthorService' in your configuration.
在配置springboot环境时出现问题,自己新建的springboot项目配置和示例项目配置近乎相同,但自己的项目启动时就会报错,无法扫描到service包的@service注解,还得在Application启动类中添加@ComponentScan注解扫描service包。
(以后埋坑,了解为什么同样的配置文件,启动会出现不同的结果)
@SpringBootApplication
@ComponentScan(basePackages = {"com.xxx.xxx.service"})
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
参考链接:https://www.cnblogs.com/nananana/p/9333917.html
文中提到的方法①实测不行,不知道是我的配置有问题还是怎么的。
找到问题了,springboot启动类扫描其所在类及所有所在类子类下的文件是没问题的,是我当时service实现类配置出错,忘记继承接口类了qaq,真渔。