如何在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>