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

      

  • 相关阅读:
    linux基础
    1-1python自动化测试环境搭建及开发工具安装
    Linux常用命令
    049.NET5_中间件
    045.NET5_基本鉴权授权
    044.NET5_基于Session_Cookies认证
    042-043.NET5_ResultFilter以及双语言应用
    041.NET5_ExceptionFilter
    040.NET5_ExceptionFilter
    039.NET5_自定义Filter匿名
  • 原文地址:https://www.cnblogs.com/achengmu/p/8315778.html
Copyright © 2011-2022 走看看