Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude a class from Spring in applicationContext?

Tags:

java

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.

But I tried the following method:

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

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?

Thanks in advance.

like image 211
Dreamer Avatar asked Oct 23 '12 15:10

Dreamer


1 Answers

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>
like image 176
Biju Kunjummen Avatar answered Nov 10 '22 07:11

Biju Kunjummen