首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

spring2 AOP 配备

2012-10-06 
spring2 AOP 配置xml方式:context:annotation-config /context:component-scan base-packagecom.anno

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");
}

}

热点排行