How do and work in Spring?

后端 未结 3 1729
轻奢々
轻奢々 2020-12-14 01:38

I have several services:

  • example.MailService
  • example.LDAPService
  • example.SQLService
  • example.WebServic
相关标签:
3条回答
  • 2020-12-14 02:09

    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 & due to XML syntax):

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

    This is a regex, so your expression ".*Service" means 'any number of any character followed by "Service"'. This explicitly excludes the MailService you want to include.

    0 讨论(0)
  • 2020-12-14 02:18

    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>
    
    0 讨论(0)
  • 2020-12-14 02:27

    Another way to perform this registration is with a single inclusion filter.

    <context:component-scan base-package="example" use-default-filters="false">
        <context:include-filter type="aspectj" expression="example..MailService*" />
    </context:component-scan>
    

    The "use-default-filters" attribute must be set to "false" in this case to keep Spring from adding a default filter equivalent to

    <context:include-filter type="annotation" 
                            expression="org.springframework.stereotype.Component"/>
    
    0 讨论(0)
提交回复
热议问题