zoukankan      html  css  js  c++  java
  • Spring-AOP教程

    1.建立工程

    2.添加依赖

    <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-aop</artifactId>
    </dependency>

    3.建立一个普通的Spring 增删改查功能

    4.在驱动类里面加一个注解,启用AutoProxy自动代理

    @EnableAspectJAutoProxy(proxyTargetClass=true)
    

    5.创建一个面向切面类 ,添加一个注解

    @Aspect   //表示是一个面向切面类
    @Component/
    
    	@Before(value = "execution(* com.example.demo.GoodsService.*(..))")//在所有方法执行之前,execution表示该包里的所有类都插入该方法
         public void beforeAdvice(JoinPoint joinPoint) { System.out.println("方法执行之前:" + joinPoint.getSignature());//获取签名 } @After(value = "execution(* com.example.demo.GoodsService.*(..))")//在所有方法执行之后调用 public void afterAdvice(JoinPoint joinPoint) { System.out.println("方法执行之前:" + joinPoint.getSignature()); } }

      

    //在方法执行之前
  • 相关阅读:
    Comparable VS Comparator
    Javascript中this关键字详解
    Runtime、System、Object
    JS IDE
    异常处理
    Throwable vs Exception
    8.4 Java 命名规范
    关键字、标识符、注释、变量
    Docker —— 从入门到实践
    RTC教程
  • 原文地址:https://www.cnblogs.com/max-hou/p/12120514.html
Copyright © 2011-2022 走看看