spring2 AOP 配置
xml方式:
<context:annotation-config />
<context:component-scan base-package="com.annotation"/>
<bean id="logInterceptor" ref="logInterceptor">
<aop:before method="before" pointcut="execution(public * com.service..*.add(..))" />
</aop:aspect>
</aop:config>
annotation方式:
<context:annotation-config />
<context:component-scan base-package="com.aop"/>
<aop:aspectj-autoproxy />
@Aspect
@Component
public class LogInterceptor {
@Pointcut("execution(public * com.service..*.add(..))")
public void myMethod(){};
@Before("myMethod()")
public void before() {
System.out.println("method before");
}
@Around("myMethod()")
public void aroundMethod(ProceedingJoinPoint pjp) throws Throwable {
System.out.println("method around start");
pjp.proceed();
System.out.println("method around end");
}
}