Hi,

I am developing my first AspectJ example, and I want to call an Aspect method before and after executing a method in another class. Let me give an example. I have in [1] the main class that invokes the |teste1()| method. I want to invoke the methods |setup()| and |cleanup()| in [2] when invoking |teste1()|. In [3], I have my |spring.xml|.

This is example is not working, and I don’t understand why? Any help to explain what am I doing wrong?

Thanks,

[1] My main class.

|package org.psc.spring; public class MyMain { public void teste1() { int a = 1; System.out.println("Var. a: " + a); } public static void main(String[] args) { MyMain main = new MyMain(); main.teste1(); } } |

[2] My AspectJ

|package org.psc.spring; public class MyMain { public void teste1() { int a = 1; System.out.println("Var. a: " + a); } public static void main(String[] args) { MyMain main = new MyMain(); main.teste1(); } } |

[3] My spring.xml

|<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xmlns:aop="http://www.springframework.org/schema/aop"; xmlns:context="http://www.springframework.org/schema/context"; xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd";> <bean id="myaop" class="org.psc.spring.MyAop"/> <aop:aspectj-autoproxy/> <aop:config> <aop:aspect id="teste1" ref="myaop"> <aop:pointcut id="setup" expression="execution(* teste1())"/> <aop:after pointcut-ref="setup" method="setup"/> </aop:aspect> </aop:config> </beans> |
_______________________________________________
aspectj-users mailing list
aspectj-users@eclipse.org
To change your delivery options, retrieve your password, or unsubscribe from 
this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Reply via email to