Announcement Announcement Module
Collapse
No announcement yet.
Aspect annotation use Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Aspect annotation use

    Hello,

    I read the spring documentation and I try to test a very easy sample, but as I am here, you can guess that I have a problem...

    In fact, I have a class and I want to test if I can do a action before the call of one method and just after.

    So I have a class like this :

    I replace the annotation sign by * because it is my first post and I can use url... This character does not pass... and I delete the url in conf file for the same reason.

    Code:
    *Aspect
    public class Test {
    
    	*Before("execute(control.business.Test.getAll())")
    	public void beforeTransaction() {
    		System.out.println("intercept before");
    	}
    	
    	*AfterReturning("control.business.Test.getAll()")
    	  public void afterTransaction() {
    		System.out.println("intercept after");
    	}
    
            public List<String> getAll() {
    ...
    }
    ...
    I have a file for the spring configuration like this :
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="...">
    
    	
    
    	<aop:aspectj-autoproxy />
    
    	<bean id="myAspect"
    		class="control.business.Test">
    		<!-- configure properties of aspect here as normal -->
    	</bean>
    
    
    </beans>
    And I read this file like the following in my main method:
    Code:
    ApplicationContext context = new ClassPathXmlApplicationContext( new String[] {"springContext.xml"} );
    The fact is that my method getAll is called, but no log are written before and after....

    Can you help me in this simple context ?

    Thank you and have a nice day !

  • #2
    With Spring AOP, the aspects are excluded from being advised. So, you will need to add another bean, modify the pointcut to select methods in that bean, and call the selected methods.

    -Ramnivas

    Comment

    Working...
    X