Results 1 to 4 of 4

Thread: problem trying to set up aop (with annotation)

  1. #1
    Join Date
    Apr 2008
    Posts
    8

    Default 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 at 02:35 PM.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Only defining a pointcut isn't going to do much. You specified the WHERE (Pointcut) to apply something but not the WHEN (before, after, ... ).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Apr 2008
    Posts
    8

    Default

    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.

  4. #4
    Join Date
    Apr 2008
    Posts
    8

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •