tags:

views:

27

answers:

2

I have several services:

  • example.MailService
  • example.LDAPService
  • example.SQLService
  • example.WebService
  • example.ExcelService

annotated wiht @Service tag.

How can i do exclude all services exept one? For example: only use MailService.
I use the next configuration:

<context:component-scan base-package="example">
    <context:include-filter type="aspectj" expression="example..MailService*" />
    <context:exclude-filter type="aspectj" expression="example..*Service*" />
</context:component-scan>

but, all services are excluded :(

Why all services are excluded if exist one rule for include MailService?

Grettings pacovr

A: 

It looks like you want to use filter type "regex". Here's an example from the Spring Reference:

<beans>

   <context:component-scan base-package="org.example">
      <context:include-filter type="regex" expression=".*Stub.*Repository"/>
      <context:exclude-filter type="annotation"
                              expression="org.springframework.stereotype.Repository"/>
   </context:component-scan>

</beans>
James Earl Douglas
A: 

Include filters are applied after exclude filters, so you have to combine both expressions into one exclude filter. AspectJ expressions allow it (& is replaced by &amp; due to XML syntax):

<context:exclude-filter type="aspectj" 
    expression="example..*Service* &amp;&amp; !example..MailService*" />
axtavt