1、aop支持注解@Aspect
xml里面必须配置
<aop:aspectj-autoproxy/>
用法,首先:声明一个切面
@Aspect
public class AspectTest{
@PointCut("execution(* com.ls.service..*.*(..))")
public void pointCut(){
}
@Before("pointCut()")
public void before(){
}
}
通知参数 JoinPointgetArgs()
(返回方法参数)、getThis()
(返回代理对象)、getTarget()
(返回目标)、getSignature()
(返回正在被通知的方法相关信息)和toString()
2、aop支持schema(项目常用的)
用法,首先:声明一个切面
public class AspectTest{public void before(LogInfo logInfo){}public void after(JoinPoint joinPoint,LogInfo logInfo){}}XML配置:
注入Bean
<bean id="testAspect" class="com.ls.aop.AspectTest"></bean>
aop设置:
<aop:config>
声明切点:
实例1.<aop:pointcut id="point" expression="execution(* com.ls.service..*.*(..))"/>//切所有service包里面的方法
实例2.<aop:pointcut id="point" expression="execution(* com.ls.service..*.*(..)) and @annotation(logInfo)"/>//切所有service包里面的带自定义注解的方法
声明切面:
<aop:aspect ref="testAspect">
<aop:after method="after" pointcut="point"></aop:after>
</aop:aspect>
</aop:config>
当在springMVC使用aop时注意:
<mvc:annotation-driven/>
<content:component-scan base-package="com.ls.service">
放在和aop同一xml里面