使用注释@SpringBootApplication进行配置 [英] Configuration using annotation @SpringBootApplication

查看:230
本文介绍了使用注释@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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆