我的 Spring Boot 配置有问题。
我使用 https://start.spring.io/ 创建了基础 Spring Boot 项目
我有一个问题,配置仅适用于子目录中的类:
我尝试过注释@ComponentScan,但没有帮助。
你知道我能用这个做什么吗?
最佳答案
Spring Boot documentation for @SpringBootApplication
状态
Many Spring Boot developers always have their main class annotated with
@Configuration
,@EnableAutoConfiguration
and@ComponentScan
. Since these annotations are so frequently used together (especially if you follow the best practices above), Spring Boot provides a convenient@SpringBootApplication
alternative.The
@SpringBootApplication
annotation is equivalent to using@Configuration
,@EnableAutoConfiguration
and@ComponentScan
with their default attributes: [...]
@ComponentScan
javadoc 状态
If specific packages are not defined, scanning will occur from the package of the class that declares this annotation.
也就是说,只会扫描与您的 ReadingListApplication
在同一包中的类型。
如果您需要自定义配置,请酌情提供您自己的 @Configuration
、@EnableAutoConfiguration
和 @ComponentScan
。
关于java - 使用注解@SpringBootApplication 进行配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33619532/