Aop代理around例子和需要jar包
需要的jar包:
aspectjrt.jar
aopalliance.jar
aspectjweaver.jar
cglib-nodep-2.1_3.jar
Aop例子:
context_aop.xml配置文件:
<bean id="fooService" /><bean id="aopInject" id="allExecution"/> <aop:around method="injectMethod" pointcut-ref="allExecution"/> </aop:aspect></aop:config>
public class AopInject { public Object injectMethod(ProceedingJoinPoint call) throws Throwable { System.out.println("AopInject类注入"); return call.proceed(); }}public class Foo { public Foo(String name, int age){ System.out.println("foo类初始化"); }}public interface FooService { Foo getFoo(String fooName, int age);}public class DefaultFooService implements FooService { public Foo getFoo(String name, int age) { return new Foo(name, age); }}BeanFactory ctx = new ClassPathXmlApplicationContext("context_aop.xml");FooService foo = (FooService) ctx.getBean("fooService");foo.getFoo("Pengo", 12);