Announcement Announcement Module
Collapse
No announcement yet.
Pointcut Rules Syntax. --> Exclusion of packages Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pointcut Rules Syntax. --> Exclusion of packages

    Hi Community!

    I have an question about an pointcut!

    I have two packages
    com.myapp.mymodule ....
    com.myapp.framework

    So i want that the pointcut will apply for all packages named com.myapp..*handlers..handlers.*Handle*.*(..)

    but not for packages named com.myapp.framework where also Handlers are inside.
    I try this:

    @Pointcut("execution(* com.myapp..handlers.*Handle*.*(..) && !(com.myapp.framework..handlers.*Handle*.*(..)))")

    I couldnīt do this: @Pointcut("execution(* com.myapp.mymodule..handlers.*Handle*.*(..))
    because someone else should use this to. So i can not specified this with the module

    But every syntax i try it comes everytime the "Pointcut is not well-formed:" exception.

    What is the right syntax for this purpose!

    Thanks a lot!

  • #2
    Separate the pointcut into two sub expressions:

    Code:
    execution(* com.myapp..handlers.*Handle*.*(..)) && !execution(* com.myapp.framework..handlers.*Handle*.*(..))

    Comment


    • #3
      Combined Pointcut Expressions

      These are my objectives:
      1. Match all constructors that take no arguments.
      2. Match all methods that are not final.

      So I came up with the following pointcut


      @Pointcut("!execution(*.new(..)) || (execution(* *(..)) && !execution(* final(..)))")

      But it still doesn't seem to avoid matching on constructor that have arguments. Any ideas why?

      Your input would be much appreciated.

      Thanks.

      Comment


      • #4
        First, you should write two separate pointcuts to express each criteria and then combine them (as a best practice).

        1. Match all constructors that take no arguments.

        execution(* new())

        2. Match all methods that are not final.

        execution(!final * *(..))

        -Ramnivas

        Comment


        • #5
          Seperated the pointcuts and still the same..

          Thanks for the reply. I tried the following.

          Pointcut 1:
          @Pointcut("execution(*.new())")
          public void invoke1()
          Pointcut 2:
          @Pointcut("execution(!final * *(..))")
          public void invoke2()
          Combing both of them:
          @Pointcut("execution(* *.invoke*(..))")
          public void invoke()
          It still didn't work. Am I combining them wrong?

          My xml conf. looks like this.

          <aop:config>
          <aop:aspect ref="theAOPLogger">
          <aop:around method="aroundAdvisor"
          pointcut="MyAdvisor.invoke()" />
          </aop:aspect>
          </aop:config>
          Your input would be much appreciated

          Comment


          • #6
            Well, there are several problems in your implementation. First of all, the way to combine pointcut is:

            Code:
            @Pointcut("invoke1() || invoke2()")
            public void invoke()
            Second, you are trying to use Spring's proxy-based weaving. That doesn't work with object construction (nor with any non-Spring beans).

            Please see Spring Framework documentation as well as AspectJ documentation for more details.

            -Ramnivas

            Comment


            • #7
              My scenario

              Thanks. I'll check on the proxy-based weaving. I don't know much about it at this point. Yes. The same configuration worked and hit all my advisors until I introduced that "constructor" need.

              I'm just trying to hit my advisors thru CGLIB proxying since I have old classes that I have no interface. This is my full config.

              <bean id="theAOPLogger"
              class="MyAdvisor.LogAdvisor" />


              <aop:aspectj-autoproxy proxy-target-class="true" />

              <bean
              class="org.springframework.aop.framework.autoproxy .BeanNameAutoProxyCreator" />

              <aop:config>
              <aop:aspect ref="theAOPLogger">
              <aop:around method="aroundAdvisor"
              pointcut="MyAdvisor.invoke()" />
              </aop:aspect>
              </aop:config>
              Is there a way to configure differently to make it work?

              Comment

              Working...
              X