zoukankan      html  css  js  c++  java
  • springboot + aspect

    第一步导入依赖

            
     <dependency>
        <groupId>aopalliance</groupId>
        <artifactId>aopalliance</artifactId>
        <version>1.0</version>
     </dependency>

    <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.8.3</version> </dependency>

    第二步写一个切面类

    package com.Aspect;
    
    import org.aspectj.lang.JoinPoint;
    import org.aspectj.lang.annotation.Aspect;
    import org.aspectj.lang.annotation.Before;
    
    /**
     * @author xulei
     * @version 1.0
     * @date 2020/3/29 22:12
     */
    @Aspect
    public class FirstAspect {
        @Before("execution(* com.Dao.*.*(..))")
        public void before(JoinPoint joinPoint){
            System.out.println("切面before方法");
        }
    }

    第三步写一个配置类(不写配置类无法切面无法生效)

    package com.config;
    
    import com.Aspect.FirstAspect;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.context.annotation.EnableAspectJAutoProxy;
    
    /**
     * @author xulei
     * @version 1.0
     * @date 2020/3/29 22:21
     */
    @EnableAspectJAutoProxy
    @Configuration
    public class AspectConfig {
            @Bean
            public FirstAspect controllerAspect(){
                return  new FirstAspect();
            }
    }
  • 相关阅读:
    新autoJS写淘宝福年种福果
    autoJS写淘宝福年种福果
    简七学理财知识
    python一键搭ftp服务器
    域名伪装
    [SWPU2019]Web1
    [网鼎杯 2020 朱雀组]phpweb
    Doc
    Docker简单使用教程
    MySQL数据库基本操作
  • 原文地址:https://www.cnblogs.com/lovetl/p/12595560.html
Copyright © 2011-2022 走看看