You're trying to use the AspectJ integration in Spring -- usually called
Spring AOP -- without actually using Spring in your program, which is just
a class with a main.

You should either use AspectJ directly (by compiling with ajc) or create a
full-blown Spring application where the advised class is managed / created
by Spring.

Regards,
Frank
Le 7 sept. 2015 18:14, "xeonmailinglist" <xeonmailingl...@gmail.com> a
écrit :

> 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"; 
> <http://www.springframework.org/schema/beans>
>        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
> <http://www.w3.org/2001/XMLSchema-instance>
>        xmlns:aop="http://www.springframework.org/schema/aop"; 
> <http://www.springframework.org/schema/aop>
>        xmlns:context="http://www.springframework.org/schema/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"; 
> <http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.1.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.1.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.1.xsdhttp://www.springframework.org/schema/jeehttp://www.springframework.org/schema/jee/spring-jee-3.1.xsdhttp://www.springframework.org/schema/oxmhttp://www.springframework.org/schema/oxm/spring-oxm-3.1.xsdhttp://www.springframework.org/schema/txhttp://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
>
_______________________________________________
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