如何在applicationContext中从Spring中排除一个类? [英] How to exclude a class from Spring in applicationContext?

查看:158
本文介绍了如何在applicationContext中从Spring中排除一个类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我们只想从某个类路径中排除一个类,比如说

Here we only want to exclude a class from certain classpath, say

com.abc.projectA.service.orderService.sectionA.orderService .class

然而,还有另一个具有相同名称但在不同类路径中的类

However there is another class with same name but in different classpath

com.abc.projectA.service.orderService.sectionB.orderService.class

因此只能按类进行文件管理名称不起作用。

so that only filer by class name is not going to work.

但我尝试了以下方法:

<context:component-scan base-package="com.abc">
    <!--other filters-->
    <!--.......-->
    <context:exclude-filter expression="projectA\.service\.orderService\.sectionA\.orderService" type="regex" />
</context:component-scan>

它不起作用。所以我打赌< context:exclude-filter> 仅在包级别有效,但对特定类没有效?如果是这样,如何从bean注入中排除一个类,以便我们可以通过类来选择连接相同的类名?

It doesn't work. So I bet the <context:exclude-filter> only valid on package level but not for specific class? If so, how to exclude a class from bean injection so that we can pick and choose with class to get wired with same class name?

提前致谢。

推荐答案

不,排除应该有效,你遇到的问题可能就是你假设正则表达式中的路径是预先的使用base-package而不是真的..只需指定完整的包

No, the exclude should work, the issue that you are having is probably that you are assuming that the path in regex will be pre-pended with the base-package which is not true..so just specify the full package

<context:component-scan base-package="com.abc">
    <!--other filters-->
    <!--.......-->
    <context:exclude-filter expression="com\.abc\.projectA\.service\.orderService\.sectionA\.orderService" type="regex" />
</context:component-scan>

这篇关于如何在applicationContext中从Spring中排除一个类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆