Announcement Announcement Module
Collapse
No announcement yet.
problem trying to set up aop (with annotation) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • problem trying to set up aop (with annotation)

    I am trying to set up an AOP configuration on my spring project.

    In the xml context file, I added :
    Code:
    <aop:aspectj-autoproxy>
    <aop:include name="myBean" />
    </aop:aspectj-autoproxy>
    My bean is clear from annotation. There are many public methods.

    Code:
    @Service("myBean")
    public class MyBean{
    public void method() {
    ...
    }
    I made a class to manage the Aop :

    Code:
    @Aspect
    public class AopClass{
    	@Pointcut("execution(public * *(..))")
    	public void createAction() {
    		System.out.println("testing aop");
    	}
    }
    When I call a public method from myBean, it doesn't call createAction() method.

    Thank you.
    Last edited by drim; Feb 26th, 2009, 02:35 PM.

  • #2
    Only defining a pointcut isn't going to do much. You specified the WHERE (Pointcut) to apply something but not the WHEN (before, after, ... ).

    Comment


    • #3
      I modified my bean like this :

      Code:
      @Aspect
      public class AopClass{
      	
      	@Pointcut("execution(public * *(..))")
          private void anyPublicOperation() {}
      	
      	 
      	@AfterReturning(package.AopClass.anyPublicOperation()")
      	public void createAction() {
      		System.out.println("BLABLA");
      	}
      }

      But the problem persists ; when I called a public method, didn't call my createAction method.

      Comment


      • #4
        It's worked.
        I modified my code like this :
        Code:
        @Aspect
        @Component
        public class AopClass{
        	
        	@Pointcut("execution(public * *(..))")
            private void anyPublicOperation() {}
        	
        	 
        	@AfterReturning(anyPublicOperation()")
        	public void createAction() {
        		System.out.println("BLABLA");
        	}
        }
        I added @Component.

        Hope it can be helpfull.

        Comment

        Working...
        X