我在 spring 配置 xml 文件中找到了这个文件,我想显式加载它,里面有这个:
<context:annotation-config/>
<context:component-scan base-package="my.path" />
我在测试中像这样加载它:
new ClassPathXmlApplicationContext(new String[]{"/beans.xml"})
问题是,显然此扫描能够看到嵌套在另一个测试中的 @Configuration
,因为此测试位于 base-package
下的包中。出于我的测试目的,这是不受欢迎的行为。有什么办法可以防止这种情况发生吗?我不使用 component-scan
来加载 @Configuration
类。
最佳答案
这个怎么样:
<context:component-scan base-package="my.path" >
<context:exclude-filter type="annotation"
expression="org.springframework.context.annotation.Configuration" />
</context:component-scan>
关于java - 如何防止Spring使用测试中的@Configuration?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28120183/