Announcement Announcement Module
Collapse
No announcement yet.
Pointcut syntax on default constructor Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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!

  • #2
    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.

    Comment


    • #3
      Thank you for answering.

      Comment

      Working...
      X