策略模式:选择动态代理还是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. Leetcode 304.二维区域和检索-矩阵不可变

    二维区域和检索 - 矩阵不可变 给定一个二维矩阵,计算其子矩形范围内元素的总和,该子矩阵的左上角为 (row1, col1) ,右下角为 (row2, col2). 上图子矩阵左上角 (row1, c ...

  2. POJ3041:Asteroids【二分图匹配】

    二分图的最大匹配=最小顶点覆盖(Konig定理)=最大独立集的补集最大匹配经典的三种模型  这题就是最小顶点覆盖,顺便这题留给我的经验就是调试的时候一定要细心细心再细心对模板的各个细节都要熟!! #i ...

  3. 只有代码不会撒谎,如何通过Spring boot源码查看其对于各个框架的默认配置

    我发现很多开发对于看源码都有种恐惧心理,其实不必这样,大部分优秀的源码写的都挺直观的,很多时候,你在搜索引擎上搜到的一些东西并不一定是对的,但源码肯定造不了假,毕竟不管你怎么想,它就在那里,该是什么意 ...

  4. CodeForces 599A Patrick and Shopping

    水题.每种情况取最小值即可. #include<cstdio> #include<cstring> #include<cmath> #include<algo ...

  5. Java子类重写父类方法注意问题收集(转)

    子类不能重写父类的静态方法,私有方法.即使你看到子类中存在貌似是重写的父类的静态方法或者私有方法,编译是没有问题的,但那其实是你重新又定义的方法,不是重写.具体有关重写父类方法的规则如下: 重写规则之 ...

  6. eclipse设置每次提交代码忽略target、.settings、.svn、.project文件

  7. 【网络】TCP的拥塞控制

    一.拥塞控制的一般原理 拥塞:对网络中某一资源的需求超过了该资源所能提供的可用部分 拥塞控制是防止过多的数据注入到网络,这样可以使网络中的路由器或链路不致过载,拥塞控制是一个全局性的过程. 流量控制往 ...

  8. redux-thunk

    1.thunk function createThunkMiddleware(extraArgument) { return ({ dispatch, getState }) => next = ...

  9. libevent HTTP client 的实现

    my_conn_ = evhttp_connection_base_new(ev_base_,ev_dns_,host,port); struct evhttp_request *http_req; ...

  10. Redis 入门指南

    就是DBIdx