Announcement Announcement Module
Collapse
No announcement yet.
apply JdkRegexpMethodPointcut to multiple beans? how? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • apply JdkRegexpMethodPointcut to multiple beans? how?

    Hi, I want to apply an advisor to multiple beans at the same time. I tried BeanNameAutoProxyCreator as follows:

    <bean id="myAutoProxyCreator"
    class="org.springframework.aop.framework.autoproxy .BeanNameAutoProxyCreator">
    <property name="beanNames">
    <value>*Manager</value>
    </property>
    <property name="interceptorNames">
    <list>
    <idref bean="myAdvisor"/>
    </list>
    </property>
    </bean>

    <bean id="advisor" class="org.springframework.aop.support.DefaultPoin tcutAdvisor">
    <property name="advice">
    <ref local="myInterceptor"/>
    </property>
    <property name="pointcut">
    <bean class="org.springframework.aop.support.JdkRegexpMe thodPointcut">
    <property name="pattern">
    <value>^org.example.service.[a-zA-Z]{1}(\\w)*Manager.(\\w)*</value>
    </property>
    </bean>
    </property>
    </bean>

    The reason why I am using JdkRegexpMethodPointcut is because there are many other Manager objects that are from the Spring and other packages. So I want to add some restriction.

    The problem is that none of my service methods get called. Am I doing something wrong? Is the above declaration correct?

    Thanks, Pete

  • #2
    Don't you get a NoSuchBeanDefinitionException?
    Shouldn't <idref bean="myAdvisor"/> be <idref bean="advisor"/>?

    Comment


    • #3
      you are right. it should be <idref bean=advisor"/> and it is in my
      application. it is a typo here only.

      i did not get any exception.

      thanks, pete

      Comment


      • #4
        Your cofiguration looks right - try testing with a simpler regular expression.

        Comment


        • #5
          Regex for a DAO method

          I made this one to look for DAO methods:

          <bean id="daoPointcut"
          class="org.springframework.aop.support.JdkRegexpMe thodPointcut">
          <property name="pattern"
          value="^[a-zA-Z0-9.]+Dao.[a-zA-Z0-9() ]+$" />
          </bean>

          Just change the "Dao" for Manager, Service, Controller, etc.

          Regards,
          Omar

          Comment

          Working...
          X