Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JUnit测试时是否排除@Component类的筛选器?_Java_Spring_Junit_Filter_Annotations - Fatal编程技术网

Java JUnit测试时是否排除@Component类的筛选器?

Java JUnit测试时是否排除@Component类的筛选器?,java,spring,junit,filter,annotations,Java,Spring,Junit,Filter,Annotations,是否可以排除@组件注释类 我想从JUnit测试中排除一个特殊类 我的项目有一个类xEventHandler,用@Component注释,我不希望spring在junit测试时使用这个类 我的ApplicationTestContext.xml如下所示: <context:component-scan base-package="com.company"> ... <context:exclude-filter expression="com\.company\.xyz\.xEv

是否可以排除
@组件
注释类

我想从JUnit测试中排除一个特殊类

我的项目有一个类
xEventHandler
,用
@Component
注释,我不希望spring在junit测试时使用这个类

我的ApplicationTestContext.xml如下所示:

<context:component-scan base-package="com.company">
...
<context:exclude-filter expression="com\.company\.xyz\.xEventHandler.java " type="regex"/>
...
</context:component-scan>

...
...
但是,由于
@Component
注释(例如,当我从该类中删除
@Component
时,该类可以工作)而被输入


我怎样才能修好它

我认为应该是:

<context:exclude-filter expression="com\.company\.xyz\.xEventHandler" type="regex"/>

IMHO最好使用配置文件(在3.1中介绍)来实现这一点:

  • test
    profile中定义这个bean
  • 通过添加
    @ActiveProfiles(“test”)
    注释,激活JUnit测试中的
    test
    配置文件
有关配置文件的更多信息:


是的……我输入了xEventHandler.java(即文件)。谢谢