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

      

  • 相关阅读:
    docker compose 配置 redis cluster jenkins
    Spring Core
    Java Case Interview two
    pytest 生成 allure报告(含4要素的对应版本,兼容)
    python中requests库的post请求 4种类型参数
    接口测试流程
    Docker学习篇 搭建jenkins
    Pytest入门 实例
    python selenium css定位6种
    python selenium select标签的下拉框和非select标签的下拉框
  • 原文地址:https://www.cnblogs.com/achengmu/p/8315778.html
Copyright © 2020-2023  润新知