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

  • Aspect annotation use


    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.

    public class Test {
    	public void beforeTransaction() {
    		System.out.println("intercept before");
    	  public void afterTransaction() {
    		System.out.println("intercept after");
            public List<String> getAll() {
    I have a file for the spring configuration like this :
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="...">
    	<aop:aspectj-autoproxy />
    	<bean id="myAspect"
    		<!-- configure properties of aspect here as normal -->
    And I read this file like the following in my main method:
    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.