Results 1 to 3 of 3

Thread: Pointcut syntax on default constructor

  1. #1
    Join Date
    Aug 2004
    Location
    Stockholm
    Posts
    466

    Default Pointcut syntax on default constructor

    Hi

    I need to define a pointcut on creation of object SystenmService, default constructor
    How do I do it?
    The purpose of this is to inject a property change listenmer on every object creation.

    This attempt doesn't crash it, but doesn't give any results either. Tried all sorts of combinations. Are there any special issues when one are setting a pointcut on a constructor? The "retVal" is not nul, but I'm not sure the method is ever called either, because I get no "Hoho" from the console.
    Code:
    @Aspect
    public class InjectPropertyChangeListenerAdvice {
    	
    	InjectPropertyChangeListenerAdvice() {
    		super();
    		System.out.println("I am!");
    	}
    
    	//	@After("execution(public se.ki.biobank.doris.domain.systemservice.SystemService.new())")
    	@AfterReturning(
    		    pointcut="execution(public se.ki.biobank.doris.domain.systemservice.SystemService.new())",
    		    returning="retVal")
    	public void injectPropertyChangeListener(Object retVal) throws Throwable {
    		Assert.notNull(retVal, "Is null");
    		System.out.println("Hoho!");
    		((SystemService)retVal).setCaption("Urban den Glade!");
        }
    }
    Stuck, help appreciated!
    Sincerely,
    /The Cantor

    "Murphy was an optimist"
    (The O'Toole commentary on Murphy's Law)

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

    Default

    If you use Spring AOP then you cannot intercept object creation, only method calls can be intercepted (due to the proxy approach) if you want this to work you will need to use loadtime or compile time weaving.
    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
    Aug 2004
    Location
    Stockholm
    Posts
    466

    Default

    Thank you for answering.
    Sincerely,
    /The Cantor

    "Murphy was an optimist"
    (The O'Toole commentary on Murphy's Law)

Posting Permissions

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