java - 使用注解@SpringBootApplication 进行配置

标签 java spring gradle spring-boot

我的 Spring Boot 配置有问题。

我使用 https://start.spring.io/ 创建了基础 Spring Boot 项目

我有一个问题,配置仅适用于子目录中的类:

enter image description here

我尝试过注释@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/

相关文章:

android - 由于 bundleReleaseJsAndAssets,APK 无法构建发布

java - relativeLayout 和 Canvas 服装 View

java - 使用流 API 分组时多个组中的单个元素

java - Lombok + QueryDsl + Mapstruct : error compiling: java. lang.NoClassDefFoundError : javax/persistence/Entity: javax. persistence.Entity

gradle - gradle jar无法找到java源

java - 'main'的 'sourceSets'方法在哪里定义的?

java - SPNEGO密码验证问题

java - 调试在 Netbeans Tomcat 中不起作用

html - 如何国际化html页面

java - 如何让 Spring 接受流畅(非 void)的 setter ?