我有一个测试类:
@ComponentScan(basePackageClasses = {MyAppConfig.class}, excludeFilters = {@ComponentScan.Filter(classes = {OtherTest.ConflictsWithAppTestConfig.class})})
...
public class MyAppTest { ... }
和另外一个不相关的测试类:
public class OtherTest {
@Configuration
public static class ConflictsWithAppTestConfig { ... }
}
具有以下目录结构:
src/java/com/example
\_ MyAppConfig.java
\_ somesubdirectory
\_ <more spring components>
...
test/java/com/example
\_ MyAppTest.java
\_ OtherTest.java // with OtherTest.ConflictsWithAppTestConfig
@ComponentScan.Filter
允许我在使用OtherTest.ConflictsWithAppTestConfig
时停止导入MyAppTest
中的@ComponentScan
。
然而,当我在同一个基础上添加更多测试用例时,维护此排除类列表将相对于@ComponentScan
在同一个包下的其他测试类增长。
如何将@ComponentScan
过滤器设置为仅包含src
目录配置,以便我手动导入test
配置?
即。填空:
@ComponentScan(..., excludeFilters = {@ComponentScan.Filter(type=???, pattern=???)}