使用@ComponentScan或< context:component-scan/>只有一个班级 [英] Using @ComponentScan or <context:component-scan /> with only one class
问题描述
我正在维护一个包含两组主要软件包的项目,该项目使用的是Spring和Spring MVC,其中一个软件包包含多个控制器,并使用XML配置(<context:component-scan />
)进行扫描.
I'm maintaining a project with two set of main packages, the project is using Spring and Spring MVC, one of these packages contains several controllers and is scanned using XML configuration (<context:component-scan />
).
问题是,另一个包中有一个类(未扫描),我需要扫描该类,但只扫描该类,而包中没有其他内容.我现在不能更改其包装,因为它现在风险太大.
The problem is that there is a single class in the other package (not scanned), and I need this class to be scanned, but only this class and nothing else in the package. I can't change its package now since it would be too risky now.
有没有办法使用注释或XML?
So is there a way to do this using annotations or XML ?
推荐答案
简单地将Bean添加为您的上下文,例如
Simply add is as a bean to your context e.g.
<bean class="my.package.MyClass" />
这篇关于使用@ComponentScan或< context:component-scan/>只有一个班级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!