@Aspect
@Component
public class testAop {
@Pointcut("execution(* com.sl.service.*.*(..))")
public void method(){}
@Around("execution(public void com.sl.service.StudentService.add(com.sl.entity.User))")
public void around(ProceedingJoinPoint p) throws Throwable {
System.out.println("around begin");
p.proceed();
System.out.println("around over");
}
@Before("execution(* com.sl.service.*.*(..))")
public void begin(){
System.out.println("before");
}
@After("method()")
public void after(){
System.out.println("after");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
">
<context:component-scan base-package="com.sl"></context:component-scan>
<aop:aspectj-autoproxy/>
</beans>
<aop:aspectj-autoproxy/>:让spring自动在所有类里找到标有@aspect的类