Spring Boot组件扫描仅包含一个类 [英] Spring boot component scan include a single class
本文介绍了Spring Boot组件扫描仅包含一个类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用spring组件扫描来自动检测Bean,如下所示:
I am using spring component scan to auto detect beans as:
@ComponentScan({"com.org.x, com.org.y"})
问题是我希望扫描com.org.x
中的所有类,但我希望从com.org.y
The issue is I want all classes in com.org.x
to be scanned but I want a single class, com.org.y.SomeService.class
, alone to be scanned from com.org.y
我该如何实现?
除了使用上下文扫描之外,如何创建这个bean并注入到应用程序上下文中?
Also apart from using context scan, how can I created this bean and inject in the application context ?
推荐答案
您应该只使用配置类中带有@Bean
注释的方法来定义bean,如
You should just define your bean using a method annotated with @Bean
in your configuration class, as explained in the documentation.
这篇关于Spring Boot组件扫描仅包含一个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文