美文网首页我爱编程
Aspect整理记录

Aspect整理记录

作者: lxqfirst | 来源:发表于2018-04-14 16:32 被阅读0次

1.引用Aspectj包

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

2.spring xml添加配置

<aop:aspectj-autoproxy proxy-target-class="true"/>
 proxy-target-class=true优先用cglib,aop会自动切换

3.定义切面

@Component
@Aspect
public class AspectLogger {
}

4.定义PointCut

/**
 *多种方式定义PointCut的value
 * 1、execution(* com.xyz.service.AccountService.*(..)) AccountService 接口的任意方法的执行
 * 2、this(com.test.spring.aop.pointcutexp.Intf)  实现了Intf接口的所有类,如果Intf不是接口,限定Intf单个类.
 * 3、within(com.test.spring.aop.pointcutexp.*) pointcutexp包里的任意类.
 * 4、@target()
 * 5、@within()
 * 6、@annotation
 * (@within和@target针对类的注解,@annotation是针对方法的注解)
 */
//例子中用的是注解
@Pointcut("@annotation(com.xxx.LoggerAnnotation)")
    public void pvAspect() {
}

5、定义行为

@Component
@Aspect
public class AspectLogger {
    private static final Logger LOGGER = LoggerFactory.getLogger(AspectLogger.class);


    //数据流出切点
    @Pointcut("@annotation(com.xxx.LoggerAnnotation)")
    public void pvAspect() {
    }

    //@Before、@Around、@After、@AfterReturning、@AfterThrowing
    @Around("pvAspect()")
    public Object rpcLog(ProceedingJoinPoint joinPoint) throws Throwable {
        //方法体
    }
}

相关文章

  • Aspect整理记录

    1.引用Aspectj包 2.spring xml添加配置 3.定义切面 4.定义PointCut 5、定义行为

  • 注解记录->Component、Aspect

    1、Component放在类上的注解,将此类实例化到spring容器当中。可以在别的service这样的类中能够注...

  • 面向切面编程AOP

    AOP知识整理 AOP(Aspect-Oriented Programming):面向切面的编程。OOP(Obje...

  • 2021-02-26nlp知识了解

    基本概念“aspect”aspect term、aspect category、aspect opinion、as...

  • Spring AOP controller层无效问题

    记录一个在使用@Aspect注解方式实现Spring MVC + Spring + jdbcTemplate读写分...

  • CleanAOP--简介

    AOP为Aspect Oriented Programming的缩写。 意为:面向切面编程。将日志记录,性能统计,...

  • 深入理解Spring事务和Spring AOP

    什么是AOP编程 Aspect Oriented Programming 面向切面编程 主要应用场景是日志记录,权...

  • Aspect

    AOP:通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术。 AOP对业务处理过程中的切面进行提取,他...

  • aspect

    可以说是面向切面编程的典范了。1 aspect修改原来的类通过消息转发实现回调2 这三个哥们是集合,但是无论怎么搞...

  • 2019-06-30 spring aop 1(spring a

    一,aop 术语 1.切面Aspect: Aspect 声明类似于 Java 中的类声明,在 Aspect 中会包...

网友评论

    本文标题:Aspect整理记录

    本文链接:https://www.haomeiwen.com/subject/lculkftx.html