gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 13:48:54 27 4
gpt4 key购买 nike

我的 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com