spring-boot - @ComponentScan是否覆盖@SpringBootApplication?

标签 spring-boot

我的@SpringBootApplication注释存在于com.abc.def包中。

根据这篇文章,使用 @SpringBootApplication 注解相当于使用 @Configuration、@EnableAutoConfiguration 和 @ComponentScan 及其默认属性:-

https://docs.spring.io/spring-boot/docs/2.0.x/reference/html/using-boot-using-springbootapplication-annotation.html

如果我提供自己的@ComponentScan,它是否会将新包添加到默认值或完全覆盖默认值?

最佳答案

@SpringBootApplication注解可以组件从Application类所属的包中扫描类。您还可以添加@ComponentScan来扫描不在Application类所属包下的类。

@ComponentScan("external.pkg")
@SpringBootApplication
class MyApp{
}

关于spring-boot - @ComponentScan是否覆盖@SpringBootApplication?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65540306/

相关文章:

spring-boot - 如何使用 Azure 事件中心创建 Spring Boot 应用程序

java - 为什么 Spring @Autowired 注入(inject)另一个对象?

java - spring boot重启时如何防止db初始化

java - spring boot init.d 脚本 start-stop-daemon : unrecognized option --no-close

java - 如何在 Spring Boot 中进行应用程序版本控制?

validation - 如何在 Spring Boot 中使用@NotNull?

spring-boot - 如何在 Spring Boot 的 JPA 存储库中编写查询?

java - 如何使用配置类中定义的方法?

java - Spring Boot JPA Hibernate CRUD 存储库中的查找表

java - Spring Boot应用程序无法启动?