App
|-src
|-com
|-xx
|-model
|-IclassA.java
|-impl
|-ClassA.java
|-test
|-com
|-xx
|-model
|-Conf.java
|-impl
|-ClassATest.java
我有一个用于生产的 XML 文件和一个用于测试的 java conf 文件
在 Conf.java 中,我有一个用于 ClassA 的 bean 减速,我在测试中使用它作为
@ContextConfiguration(classes = Conf.class)
在 xml 中我有 <context:component-scan base-package="com.xx.*" />
,问题在于此扫描也在扫描测试文件夹并识别出我有 2 个 ClassA 减速,一个在 XML 中,一个在 Conf.java 文件中。
有没有排除test文件夹的扫描?
最佳答案
尝试使用context:exclude-filter
<context:component-scan base-package="com.xx.*">
<context:exclude-filter type="regex" expression="**.*Test"/>
</context:component-scan>
关于java - 如何在 spring 中从组件扫描注释中排除测试文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37433771/