AspectJ Don't working. Please help me. Where my mistakes?
Код | package springtestapp1;
import org.aspectj.lang.annotation.*;
@Aspect public class Audence{ public Audence(){}
@Pointcut("execution(* *.performance())") public void performance(){ System.out.println("---Main Method!---"); }
@Before("performance()") void before(){ System.out.println("---Before Method---"); }
@After("performance()") void after(){ System.out.println("---After Method---"); }
public static void main(String[] arg){ Audence au = new Audence(); au.performance(); } }
|
Spring AOP don't working too! :(
Код | <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<bean id="myBean" class="mypackage.MyClass" />
<aop:aspectj-autoproxy/> <aop:config> <aop:aspect ref="myBean"> <aop:before method="myBeforeMethod()" pointcut="execution(* mypackage.*.myMainMethod(..))"/> </aop:aspect> </aop:config> </beans>
|
Код | package mypackage;
/** * * @author User */ public class MyClass{
public void myMainMethod(){ System.out.println("This is my mainly method."); }
public void myBeforeMethod(){ System.out.println("... and this is my before method."); }
public static void main(String[] args){ ApplicationContext ac = new FileSystemXmlApplicationContext("myBeans.xml"); MyClass my = null;
try{ my = (MyClass)ac.getBean("myBean");
} catch(Exception ex){ System.out.println(ex.toString()); System.exit(); }
my.myMainMethod(); }
}
|
Requirement result:
Код | ... and this is my before method. This is my mainly method.
|
--------- Only AspectJ with *.aj files works on Netbeans. |