zoukankan      html  css  js  c++  java
  • spring: 使用Aspectj代理EnabelAspectjAutoProxy

    使用JavaConfig的话,可以在配置类的类级别上通过使用EnableAspectJ-AutoProxy注解启用自动代理功能。

    package ch2.test;
    
    import org.aspectj.lang.annotation.AfterReturning;
    import org.aspectj.lang.annotation.AfterThrowing;
    import org.aspectj.lang.annotation.Aspect;
    import org.aspectj.lang.annotation.Before;
    import org.aspectj.lang.annotation.Pointcut;
    
    @Aspect
    public class Audience {
    
    	
    	//定义命名的切点
    	@Pointcut("execution(** ch2.test.Performance.perform(..))")
    	public void Performance(){}
    	
    	//表演开始之前:关闭手机
    	@Before("Performance()")
    	public void silenCellPhones()
    	{
    		System.out.println("silen cell phones");
    	}
    	
    	//表演开始之前:入座
    	@Before("Performance()")
    	public void takingSeats()
    	{
    		System.out.println("take seats");
    	}
    	
    	//表演开始之后:鼓掌
    	@AfterReturning("Performance()")
    	public void applause()
    	{
    		System.out.println("clap clap clap");
    	}
    	
    	//表演结束之后:表演失败退票
    	@AfterThrowing("Performance()")
    	public void demandRefund()
    	{
    		System.out.println("demand refund");
    	}
    	
    }
    

      

    config

    package ch2.test;
    
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.context.annotation.EnableAspectJAutoProxy;
    
    @Configuration
    @ComponentScan
    //声明自动代理: 开启自动代理
    @EnableAspectJAutoProxy
    public class ConcertConfig {
    
    	@Bean
    	public Audience audience()
    	{
    		return new Audience();
    	}
    }
    

      

  • 相关阅读:
    Java微信分享接口开发
    lintcode 刷题 by python 部分链表题总结(2)
    基于CART的回归和分类任务
    机器学习: K-means 聚类
    python 中的堆 (heapq 模块)应用:Merge K Sorted Lists
    名人、皇家谱系
    python实现数组和链表的归并排序
    Python 正则 —— 捕获与分组
    ArcGIS中的数据连接问题——数据类型不统一
    Spring boot 搭建
  • 原文地址:https://www.cnblogs.com/achengmu/p/8315778.html
Copyright © 2011-2022 走看看