Announcement Announcement Module
Collapse
No announcement yet.
Mixing AspectJ and XML style Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mixing AspectJ and XML style

    Hi,

    I want to write a logging aspect class which defines the logging methods and the advices. Since I want the pointcouts (which methods shall be logged) being configurable I cannot declare them as annotation.
    So is it possible to declare the pointcuts in XML?

    Thx.

  • #2
    In case you are using aspectj with spring, yes it is possible to declare pointcut in xml.

    Comment


    • #3
      The problem is that I do not know how to mix...

      Code:
      @Aspect
      public class TestAspect {
        @After("finally()")
        public void doit() {
        }
      }
      
      <bean id="testAspect" class="TestAspect" autowire="byType"></bean>
      
      <aop:config>
        <aop:pointcut id="finally" expression="execution(public * Service1.delete(..))"/>
      </aop:config>
      I get the error: can't find referenced pointcut finally

      Comment


      • #4
        Why not do the following?

        Code:
        <aop:config>
          <aop:aspect ref="testAspect">
              <aop:after method="doIt" pointcut="execution(public * Service1.delete(..))"/>
          </aop:config>
        </aop:config>
        -Ramnivas

        Comment


        • #5
          Yes, of couse. But then the complete AOP stuff in in XML style, not annotations at all.

          Comment


          • #6
            What is the use case that you are trying to address? Specifically, what do you want to gain by using annotations?

            I do see a possibility of supporting abstract/concrete aspect idea, where you would define an abstract pointcut in an abstract aspect and then specify the definition for the pointcut in a subaspect defined using XML syntax (a similar idea is currently available in AspectJ). This is currently not supported in AspectJ-style Spring AOP, but if there is compelling use case, I can imagine supporting it in a future version.

            -Ramnivas

            Comment


            • #7
              Originally posted by ramnivas View Post
              I do see a possibility of supporting abstract/concrete aspect idea, where you would define an abstract pointcut in an abstract aspect and then specify the definition for the pointcut in a subaspect defined using XML syntax (a similar idea is currently available in AspectJ).
              This is what i meant. Thx. So I will use XML.

              Comment

              Working...
              X