使用注释@SpringBootApplication进行配置 [英] Configuration using annotation @SpringBootApplication
问题描述
我使用
我已经尝试了注释 @ComponentScan
你知道我能做些什么吗?
Spring Boot文档用于 @SpringBootApplication
州
许多Spring Boot开发人员总是使用
@Configur标注
,
主类ation@EnableAutoConfiguration
和@ComponentScan
。
由于这些注释经常一起使用(特别是如果
遵循上述最佳实践),Spring Boot提供了一个
方便的@SpringBootApplication
替代。
@SpringBootApplication
注释相当于使用
@Configuration
,@EnableAutoConfiguration
和@ComponentScan
及其
默认值属性:[...]
其中 @ComponentScan
javadoc states
如果未定义特定包,则将从声明此批注的类的
包中进行扫描。
也就是说,只有与 ReadingListApplication
将被扫描。
如果您想要自定义配置,请提供您自己的 @Configuration
, @EnableAutoConfiguration
和 @ComponentScan
,如果适用的话。
I have problem with Spring Boot configuration.
I have created base Spring Boot project using https://start.spring.io/
And I have a problem, configuration works only for classes in sub catalog:
I have tried annotation @ComponentScan but it didn't help.
Do You have any idea what can I do with this?
The Spring Boot documentation for @SpringBootApplication
states
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: [...]
where the @ComponentScan
javadoc states
If specific packages are not defined, scanning will occur from the package of the class that declares this annotation.
That is, only the types that are in the same package as your ReadingListApplication
will be scanned.
If you want a custom configuration, provide your own @Configuration
, @EnableAutoConfiguration
, and @ComponentScan
, as appropriate.
这篇关于使用注释@SpringBootApplication进行配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!