JUnit 测试时@Component 类的排除过滤器? [英] Exclude-filter for a @Component class while JUnit testing?
本文介绍了JUnit 测试时@Component 类的排除过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以排除带有@Component
注释的类?
is it possible to exclude a @Component
annotated class?
我想从 JUnit 测试中排除一个特殊的类.
i would like to exclude a special class from JUnit testing.
我的项目有一个类 xEventHandler
用 @Component
注释,我不希望 spring 在 junit 测试时使用这个类.
my project has a class xEventHandler
annotated with @Component
and i dont want spring to use this class while junit testing.
我的 ApplicationTestContext.xml 如下所示:
my ApplicationTestContext.xml looks like this:
<context:component-scan base-package="com.company">
...
<context:exclude-filter expression="com\.company\.xyz\.xEventHandler.java " type="regex"/>
...
</context:component-scan>
但是,由于 @Component
注释而进入该类(例如,当我从该类中删除 @Component
时有效).
however, the class gets entered because of the @Component
annotation(e.g. works, when i delete the @Component
from that class).
我该如何解决?
推荐答案
我认为应该是:
<context:exclude-filter expression="com\.company\.xyz\.xEventHandler" type="regex"/>
这篇关于JUnit 测试时@Component 类的排除过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文