aspectj

8 -- 深入使用Spring -- 4...6 AOP代理:基于注解的XML配置文件的管理方式

时光毁灭记忆、已成空白 提交于 2020-01-05 05:46:42
      8.4.6 基于XML配置文件的管理方式         Spring 2.x 提供一个新的aop:命名空间来定义切面、切入点和增强处理。         XML配置方式优点:           ⊙ 如果应用没有使用JDK 1.5 以上版本,那么应用只能使用XML配置方式来管理切面、切入点和增强处理等。           ⊙ 采用XML配置方式时对早期的Spring用户来说更加习惯,而且这种方式允许使用纯粹的POJO来支持AOP。当使用AOP作为工具来配置企业服务时,XML会是一个很好的选择。         当使用XML风格时,可以在配置文件中清晰地看出系统中存在那些切面。         XML配置费方式缺点:           ⊙ 使用XML配置方式不能将切面、切入点、增强处理等封装到一个地方。如果需要查看切面、切入点、增强处理,必须同时结合Java文件和XML配置文件来查看;但使用@AspectJ时,则只需要一个单独的类文件即可看到切面、切入点和增强处理的全部信息。           ⊙ XML配置方式比@AspectJ方式有更多的限制:仅支持“singleton”切面Bean,不能在XML中组合多个命名连接点的声明。         @AspectJ切面还有一个优点,就是能被Spring AOP和AspectJ同时支持

Spring AOP小记

淺唱寂寞╮ 提交于 2020-01-05 05:41:21
一、概述 在通常的开发过程中,我们调用的顺序通常是controller->service-dao,其中,service中包含着太多的业务逻辑,并且还要不断调用dao来实现自身的业务逻辑,经常会导致业务耗时过久,在aop出现之前,方式一般是在函数中开始写一个startTime,结尾再写一个endTime来查看执行该函数的耗时,过多的使用此类方式会导致代码的耦合性太高,不利于管理,于是,AOP(面向切面)出现了。AOP关注的是横向的,而OOP的是纵向。 Spring自2.0版本开始采用@AspectJ注解非常容易的定义一个切面。@AspectJ注解使用AspectJ切点表达式语法进行切点定义,可以通过切点函数、运算符、通配符等高级功能进行切点定义,拥有强大的连接点描述能力。 1.1 特点 AOP(Aspect Oriented Programming)面向切面编程,通过预编译方式和运行期动态代理实现程序功能的横向多模块统一控制的一种技术。AOP是OOP的补充,是Spring框架中的一个重要内容。利用AOP可以对业务逻辑的各个部分进行隔离,从而使得业务逻辑各部分之间的耦合度降低,提高程序的可重用性,同时提高了开发的效率。AOP可以分为静态织入与动态织入,静态织入即在编译前将需织入内容写入目标模块中,这样成本非常高。动态织入则不需要改变目标模块。Spring框架实现了AOP

Spring aop

此生再无相见时 提交于 2020-01-05 05:38:51
AOP 概念 1 aop :面向切面(方面)编程,扩展功能不修改源代码实现 2 AOP采取横向抽取机制,取代了传统纵向继承体系重复性代码 3 aop 底层使用动态代理实现 ( 1 )第一种情况,有接口情况,使用动态代理创建接口实现类代理对象 ( 2 )第二种情况,没有接口情况,使用动态代理创建类的子类代理对象 AOP 原理 画图分析原理 AOP 操作术语 Joinpoint( 连接点 ): 类里面可以被增强的方法,这些方法称为连接点 Pointcut( 切入点 ) : 所谓切入点是指我们要对哪些 Joinpoint 进行拦截的定义 . Advice( 通知 / 增强 ): 所谓通知是指拦截到 Joinpoint 之后所要做的事情就是通知 . 通知分为前置通知 , 后置通知 , 异常通知 , 最终通知 , 环绕通知 ( 切面要完成的功能 ) Aspect( 切面 ): 是切入点和通知(引介)的结合 Introduction( 引介 ): 引介是一种特殊的通知在不修改类代码的前提下 , Introduction 可以在运行期为类动态地添加一些方法或 Field. Target( 目标对象 ): 代理的目标对象 ( 要增强的类 ) Weaving( 织入 ): 是把增强应用到目标的过程 . 把 advice 应用到 target 的过程 Proxy (代理) : 一个类被 AOP

Spring 学习(三)AOP

房东的猫 提交于 2020-01-05 05:38:23
(1)AOP概述   - AOP:面向切面编程,扩展功能不修改源代码实现   - AOP采取 横向抽取机制 ,取代了传统的 纵向继承体系 重复性代码 (2)AOP底层原理     原始方法-------》纵向继承体系          横向机制: JDK代理机制:jdk动态代理是由 Java 内部的反射机制来实现的.jdk动态代理的应用前提,必须是目标类基于统一的接口。如果没有上述前提,jdk动态代理不能应用。 CGlib代理机制:Cglib的原理是对指定的目标类动态生成一个子类,并覆盖其中方法实现增强,但因为采用的是继承,所以不能对final修饰的类和final方法进行代理。        (3)AOP操作相关术语(重点切入点、增强、切面) spring的AOP操作(基于aspectj的XML方式) Joinpoint 连接点:类里面可以被增强的方法,这些方法称为连接点 Pointcut 切入点:在类里面可以有很多的方法被增强,但是在实际的操作中值只是增强了add()和update(),则这两个实际增强的方法称为切入点 Advice 通知/增强:实际增强的逻辑,称为增强,例如扩展日志的功能,这个日志功能称为增强        分为: (1)前置通知:在方法之前执行      (2)后置通知:在方法之后执行      (3)异常通知:方法出现异常      (4)最终通知

Spring AOP介绍

吃可爱长大的小学妹 提交于 2020-01-05 05:31:24
1、介绍 AOP(面向切面编程)对OOP(面向对象编程)是一种补充,它提供了另一种程序结构的思路。OOP的模块单元是class,而AOP的模块单元是aspect。Spring中一个关键的组件是AOP框架,然而,Spring IoC容器并不依赖于AOP,也就是说如果你不想用AOP的话可以不用。 在Spring框架中AOP用来做什么呢? 提供声明式的企业服务,特别是代替EJB的声明式服务。最重要的的服务是声明式事务管理。 允许用户实现自定义的aspect 1.1、AOP概念 Aspect(方面):横切多个class的一个关注点的模块化。事务管理是一个很好的例子。在Spring AOP中,aspect可以用普通类或者带有@Aspect注解的普通类来实现。 Join point(连接点):程序执行期间的一个点,比如方法的执行或者异常的处理。在Spring AOP中,一个连接点总是代表一个方法执行。 Advice(通知):一个aspect在一个特定的连接点所采取的动作。通知的类型包括"around"、"before"、"after"。许多AOP框架,包括Spring也是,它们把一个通知作为一个拦截器,维护一个拦截器链环绕在连接点上。 Pointcut(切入点):匹配连接点的一个谓词。Advice关联一个切点表达式。Spring默认用AspectJ切点表达式。 Target object

Spring Aop “Around.class” Class Not Found Exception

青春壹個敷衍的年華 提交于 2020-01-05 04:23:05
问题 Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.config.internalAutoProxyCreator': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/aspectj/lang

Java class file truncated

送分小仙女□ 提交于 2020-01-05 04:18:09
问题 I have two projects. My one project (say project2) depends on another project(project2). Both projects are maven project and project1 is listed in dependancies of project2. When I compile project2, all the class files from project1 should be copied to project2 (I imagine). But, I see that the file size of one of the class files in project1 is different than file size of class file for the same class in project2. If I decompile the files I get following results. Decompiled FacebookUserDetail

Eclipse debug stepping with AspectJ

こ雲淡風輕ζ 提交于 2020-01-03 18:42:34
问题 I have Eclipse setup with "The AspectJ Development Tools" plugin. I'm trying to debug some code that uses AspectJ and step through it, but it is unable to match up the source lines since AspectJ has added extra stuff at compile time. No one else seems to be complaining about what seems like a major flaw (being unable to debug!), so I'm hoping I just need to tweak something to make it work. What am I doing wrong? 回答1: Yes, this is a bug with AspectJ. Stepping through advice has the incorrect

When I apply AspectJ to Android project with Androidannotations not work

依然范特西╮ 提交于 2020-01-03 17:17:24
问题 I'm using Androidstudio 0.8.9 and build with gradle. I was using Android-Annotations and works well. And I want use AspectJ also, so apply plugin(https://github.com/uPhyca/gradle-android-aspectj-plugin). But compile fail, and throw some error message :app:compileDebugJava Internal compiler error: java.lang.IllegalStateException: java.lang.IllegalArgumentException: Unknown location : SOURCE_OUTPUT at org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.BatchAnnotationProcessorManager

Trying to match an AspectJ pointcut signature for any methods containing a variable

南楼画角 提交于 2020-01-03 17:12:26
问题 I want to create a pointcut that matches any method in my Web controller that contains a ModelMap: pointcut addMenu(ModelMap modelMap) : execution (public String example.web.MyController.*(..)) && args (modelMap); before(ModelMap modelMap) : addMenu(modelMap) { // Do stuff with modelMap... } My problem is that this only matches methods with ONLY the ModelMap parameter, others are not matched because they contain too many parameters. For example, this is not intercepted, due to the "req"