手机网站建设教程北京发生大事了
注解方式AOP基本使用
Spring的AOP也提供了注解方式配置,使用相应的注解代替之前的xml配置。
xml配置:
    <aop:config>
<!--        配置切入点  目的是指定哪些方法增强--><aop:pointcut id="myPointCut1" expression="execution(void com.hsf.service.Impl.UserServiceImpl.show01())"/><aop:aspect ref="advice"><aop:before method="beforeAdvice" pointcut-ref="myPointCut1"></aop:before></aop:aspect></aop:config> 
注解配置:
<!--    注解包扫描--><context:component-scan base-package="com.hsf"></context:component-scan>
<!--    配置AOP注解自动代理  --><aop:aspectj-autoproxy></aop:aspectj-autoproxy> 
@Component("myadvice")
@Aspect
public class MyAdvice {//增强方法@Before("execution(void com.hsf.service.Impl.UserServiceImpl.show01())")public void beforeAdvice(JoinPoint joinPoint){System.out.println("当前目标对象"+joinPoint.getTarget());System.out.println("表达式"+joinPoint.getStaticPart());System.out.println("前置的增强");} 

注解方式AOP配置详解
//前置增强方法@Before("execution(void com.hsf.service.Impl.UserServiceImpl.show01())")//后置通知@AfterReturning(pointcut = "execution(void com.hsf.service.Impl.UserServiceImpl.show01())")//环绕通知@Around( "execution(void com.hsf.service.Impl.UserServiceImpl.show01())")//异常抛出通知@AfterThrowing(pointcut ="execution(void com.hsf.service.Impl.UserServiceImpl.show01())", throwing = "e")//最终通知@After("execution(void com.hsf.service.Impl.UserServiceImpl.show01())") 
切点表达式的抽取:
  //切点表达式的抽取@Pointcutpublic void myPointCut(){} 
调用抽取的表达式:

配置类,全注解开发
@Configuration
@ComponentScan("com.hsf")//  <context:component-scan base-package="com.hsf"></context:component-scan>
@EnableAspectJAutoProxy//<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
public class SpringConfig {
} 
注解方式AOP原理剖析

