【问题标题】:How to exclude test folder from component scan annotation in spring如何在春季从组件扫描注释中排除测试文件夹
【发布时间】:2016-09-22 20:37:20
【问题描述】:
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 文件中。

是否可以排除对测试文件夹的扫描?

【问题讨论】:

  • 我想知道潜在的问题是否可能是您的测试类在您的运行时类路径上。
  • 我用 intellij 作为 spring 创建了项目 .. 没有改变任何东西

标签: java xml spring applicationcontext component-scan


【解决方案1】:

尝试使用context:exclude-filter

<context:component-scan base-package="com.xx.*">
    <context:exclude-filter type="regex" expression="**.*Test"/>
 </context:component-scan>

【讨论】:

  • 您确定关于 **.*Test 吗?我收到了一个错误
猜你喜欢
  • 1970-01-01
  • 2021-07-23
  • 2016-08-13
  • 2013-07-08
  • 1970-01-01
  • 1970-01-01
  • 2017-07-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多