AOP 切面技术 spring

AOP 切面技术

依赖

 spring-aop

 spring-context

 spring-webmvc

 aspectjrt

 aspectjweaver

接口 mapper文件的建立

省略

切面的创建

 @Aspect //声明切面

 @Component

 @EnableAspectJAutoProxy(proxyTargetClass = true) //切面代理自动生成

 class AspectJ {

  /**

   * 声明切点

   */

  @Pointcut("execution(* com.aop.mapper.*.*(..))")

  void aop(){}

  /**

   * 前置通知哦

   * @param joinPoint

   */

  @Before("aop()")

  void print(JoinPoint joinPoint){

    System.err.println("进行dao层访问")

  }

 }

要开启自动扫描包 applicationContext.xml

<context:component-scan base-package="包路径"/>

打印LOG日志的依赖

<dependency>

        <groupId>ch.qos.logbackgroupId>

        <artifactId>logback-coreartifactId>

        <version>${logback.version}version>

    dependency>

    <dependency>

        <groupId>ch.qos.logbackgroupId>

        <artifactId>logback-classicartifactId>

        <version>${logback.version}version>

    dependency>

    <dependency>

        <groupId>ch.qos.logbackgroupId>

        <artifactId>logback-accessartifactId>

        <version>${logback.version}version>

    dependency>

    <dependency>

        <groupId>org.slf4jgroupId>

        <artifactId>slf4j-apiartifactId>

        <version>${slf4j.version}version>

    dependency>

    <dependency>

        <groupId>org.slf4jgroupId>

        <artifactId>jcl-over-slf4jartifactId>

        <version>${slf4j.version}version>

    dependency>

spring boot 中我们使用
logging:level:包名:日志级别

你可能感兴趣的:(学习笔记)