策略模式:选择动态代理还是CGLIB方式:

1、这种在运行时,动态地将代码切入到类的指定方法、指定位置上的编程思想就是面向切面的编程。

2、AOP基本上是通过代理机制实现的

3、写好验证用户的代码,然后告诉Spring你要把这段代码加到哪几个地方(execution处),Spring就会帮你加过去,而不要你自己Copy过去

4、在与mybatis的结合中,可以通过配置AOP生成事务代理,<tx:advice>配置AOP中的通知。

<aop:advisor advice-ref="txAdvice"

pointcut-ref="interceptorPointCuts" />

4、注解的方式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
@Aspect
public class Log {
    @Before("execution(* cn.sxt.service.impl.*.*(..))")
    public void before(){
        System.out.println("-----方法执行前-----");
    }
    @After("execution(* cn.sxt.service.impl.*.*(..))")
    public void after(){
        System.out.println("-----方法执行后-----");
    }
    @Around("execution(* cn.sxt.service.impl.*.*(..))")
    public Object aroud(ProceedingJoinPoint jp) throws Throwable{
        System.out.println("环绕前");
        System.out.println("签名:"+jp.getSignature());
        //执行目标方法
         Object result = jp.proceed();
        System.out.println("环绕后");
        return result;
    }
}

<wiz_tmp_tag class="wiz-block-scroll">

 
1
2
3
4
5
6
7
8
9
<bean id="log" class="cn.sxt.log.Log"/>
<bean id="afterLog" class="cn.sxt.log.AfterLog"/>
 <!--<bean id="exceptionlog" class="cn".sxt.log.ExceptionLog></bean> -->
<aop:config>
    <aop:pointcut expression="execution(* cn.sxt.service.impl.*.*(..))" id="pointcut"/>
     <!--<aop:advisor advice-ref="exceptionlog" pointcut-ref="pointcut"/> -->
    <aop:advisor advice-ref="log" pointcut-ref="pointcut"/>
    <aop:advisor advice-ref="afterLog" pointcut-ref="pointcut"/>
</aop:config>
1
2
3
4
5
6
7
8
9
10
<bean id="userService" class="cn.sxt.service.impl.UserServiceImpl"/>
<bean id="log" class="cn.sxt.log.Log"/>
<aop:aspectj-autoproxy/>
<!--<aop:config>-->
    <!--<aop:aspect ref="log">-->
        <!--<aop:pointcut expression="execution(* cn.sxt.service.impl.*.*(..))" id="pointcut"/>-->
        <!--<aop:before method="before" pointcut-ref="pointcut"/>-->
        <!--<aop:after method="after" pointcut-ref="pointcut"/>-->
    <!--</aop:aspect>-->
<!--</aop:config>-->

 

Spring-AOP解析的更多相关文章

  1. Spring框架IOC容器和AOP解析 非常 有用

    Spring框架IOC容器和AOP解析   主要分析点: 一.Spring开源框架的简介  二.Spring下IOC容器和DI(依赖注入Dependency injection) 三.Spring下面 ...

  2. Spring系列(五):Spring AOP源码解析

    一.@EnableAspectJAutoProxy注解 在主配置类中添加@EnableAspectJAutoProxy注解,开启aop支持,那么@EnableAspectJAutoProxy到底做了什 ...

  3. Spring AOP源码分析(二):AOP的三种配置方式与内部解析实现

    AOP配置 在应用代码中,可以通过在spring的XML配置文件applicationContext.xml或者基于注解方式来配置AOP.AOP配置的核心元素为:pointcut,advisor,as ...

  4. 曹工说Spring Boot源码(18)-- Spring AOP源码分析三部曲,终于快讲完了 (aop:config完整解析【下】)

    写在前面的话 相关背景及资源: 曹工说Spring Boot源码(1)-- Bean Definition到底是什么,附spring思维导图分享 曹工说Spring Boot源码(2)-- Bean ...

  5. 源码解析Spring AOP的加载与生效

    本次博主主要进行Spring AOP这里的解析,因为在工作中使用后,却不知道背后的实现原理并在使用的过程中发现了一些认知缺陷,所以决定写这么一篇文章以供大家参考参考,进入正题. 本次博主使用了@Asp ...

  6. Spring框架IOC容器和AOP解析

    主要分析点: 一.Spring开源框架的简介  二.Spring下IOC容器和DI(依赖注入Dependency injection) 三.Spring下面向切面编程(AOP)和事务管理配置  一.S ...

  7. Spring AOP中pointcut expression表达式解析

    Pointcut 是指那些方法需要被执行"AOP",是由"Pointcut Expression"来描述的. Pointcut可以有下列方式来定义或者通过&am ...

  8. Spring AOP中pointcut expression表达式解析 及匹配多个条件

    Spring中事务控制相关配置: <bean id="txManager" class="org.springframework.jdbc.datasource.D ...

  9. jdk动态代理与cglib代理、spring aop代理实现原理解析

    原创声明:本博客来源为本人原创作品,绝非他处摘取,转摘请联系博主 代理(proxy)的定义:为某对象提供代理服务,拥有操作代理对象的功能,在某些情况下,当客户不想或者不能直接引用另一个对象,而代理对象 ...

  10. Spring AOP中 pointcut expression表达式解析

    任意公共方法的执行: execution(public * *(..)) 任何一个以“set”开始的方法的执行: execution(* set*(..)) AccountService 接口的任意方 ...

随机推荐

  1. DataTable 转JSON数据

    /// <summary> /// 将datatable转换为json /// </summary> /// <param name="dtb"> ...

  2. HDU 3397 双lazy标记的问题

    题目大意 对一个只有0和1的序列,支持以下几种操作1.将区间所有的值变成12.将区间所有的值变为03.将区间的0和1翻转(0变成1 1变成0)4.求区间中1的个数5.求区间连续最长的1的个数 http ...

  3. ES6__函数的扩展

    /** * 函数的扩展 * 1 为函数参数指定默认值 * 2 函数的 rest 参数 * 3 箭头函数 */ // ------------------------------------------ ...

  4. 转 蓝桥杯 历届试题 波动数列 [ dp ]

    传送门   历届试题 波动数列   时间限制:1.0s   内存限制:256.0MB     锦囊1   锦囊2   锦囊3   问题描述 观察这个数列: 1 3 0 2 -1 1 -2 ... 这个 ...

  5. 通过分析exevc系统调用处理过程来理解Linux内核如何装载和启动一个可执行程序

    前言说明 本篇为网易云课堂Linux内核分析课程的第七周作业,本次作业我们将具体来分析exec*函数对应的系统调用处理过程,来分析Linux内核如何来执行一个可执行程序,由于有一个在网易云课堂共同学习 ...

  6. 使用DataOutputStream输出流的read方法出现读取字节不一致解决办法,本地和测试环境不一致

    之前: DataInputStream in = new DataInputStream(connection.getInputStream());    byte[] b = new byte[in ...

  7. 洛谷—— P1656 炸铁路

    P1656 炸铁路 题目描述 因为某国被某红色政权残酷的高压暴力统治.美国派出将军uim,对该国进行战略性措施,以解救涂炭的生灵. 该国有n个城市,这些城市以铁路相连.任意两个城市都可以通过铁路直接或 ...

  8. [Bzoj1034][ZJOJ2008]泡泡堂BNB(贪心)

    1034: [ZJOI2008]泡泡堂BNB Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3482  Solved: 1776[Submit][St ...

  9. vue学习001 --环境搭建

    系统 : win cmd: cmder 链接:https://cmder.net/ 1.安装node.js 链接地址: http://cdn.npm.taobao.org/dist/node/v10. ...

  10. 条款一:尽量使用const、inline而不是#define

    #define ASPECT_RATIO 1.653 编译器会永远也看不到ASPECT_RATIO这个符号名,因为在源码进入编译器之前,它会被预处理程序去掉,于是ASPECT_RATIO不会加入到符号 ...