aspectj

Set an AspectJ advise for static method

我与影子孤独终老i 提交于 2019-11-30 04:45:26
问题 I have written simple Aspect with primitive Pointcut and Advise method: @Aspect public class MyAspect { @Pointcut("execution(static * com.mtag.util.SomeUtil.someMethod(..))") public void someMethodInvoke() { } @AfterReturning(value = "someMethodInvoke())", returning = "comparisonResult") public void decrementProductCount(List<String> comparisonResult) { //some actions } } I have following Spring annotation-based application config: @Configuration @EnableAspectJAutoProxy public class AppConfig

AspectJ: How to weave an aspect library into a Java project

一世执手 提交于 2019-11-30 03:57:04
问题 I build small library (Java and Maven) - using AspectJ. Library must be independent. Library deliver Aspects and Annotations. Function of library is - "call advice when executed a method with specific annotation". All is ok when I use everything in one module, but problem appers when i separate library and project with classes which advice must be applied. I create simple schema. Library B - my library (aspects and annotations) Project A - project with buisness methods which adivce must be

aspectj pointcut with annotation parameters

房东的猫 提交于 2019-11-30 03:40:07
I am using aspectj to intercept methods that are annotated with @Profile(description="something") @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Profile { public String description() default ""; } @Around("com.merc.aop.ctw.aspect.PointcutDefinitions.logAnnotatedMethods(profile)") public Object profile(ProceedingJoinPoint pjp, Profile profile) throws Throwable { .... } @Pointcut("@annotation(com.merc.annotations.Profile)") protected void logAnnotatedMethods(Profile profile) { } But I get the following error msg while compileing using AJC formal unbound in

Using AspectJ logging without Spring

淺唱寂寞╮ 提交于 2019-11-30 03:26:28
问题 I have just working on an old application which has poor log or no logs. It does not implement Spring framework. Is it possible to implement AspectJ logging functionality without Spring? If yes please suggest me some good tutorials. 回答1: try this link for a simple application showing use of Load time weaving without using Spring http://ganeshghag.blogspot.in/2012/10/demystifying-aop-getting-started-with.html all that would be needed is aspectj runtime and weaver jars, and a META-INF\aop.xml

Spring中的AOP(一)——AspectJ的基本使用

戏子无情 提交于 2019-11-30 02:07:36
AOP(Aspect Orient Programming),也就是面向切面编程,作为面向对象编程的一种补充,当前已经成为一种比较成熟的编程思想,其实AOP问世的时间并不长,甚至在国内的翻译还不太统一(另有人翻译为“面向方面编程”)。AOP和OOP(Object Orient Programming,面向对象编程)互为补充,OOP将程序分解成各个层次的对象,而AOP则将程序运行过程分解成各个切面。可以这样理解:OOP是从静态角度考虑程序结构,而AOP则从动态角度考虑程序运行过程。 为什么需要AOP 在传统OOP变成立,以对象为核心,整个软件系统由系列相互依赖的对象组成,而这些对象被抽象成一个一个的类,并允许使用类继承来管理类与类之间从一般到特殊的关系。随着软件规模的增大,应用的逐渐升级,慢慢出现了一些OOP很难解决的问题。 我们可以通过分析、抽象出一系列具有一定属性与行为的对象,并通过这些对象之间的协作来形成一个完整的软件功能。由于对象可以继承,因此我们可以把具有相同功能或相同特性的属性抽象到一个层次分明的类结构体系中。随着软件规模的不断扩大,专业化分工越来越系列,以及OOP应用实践的不断增多,随之也暴露出一些OOP无法很好解决的问题。 假设系统中有3段完全相似的代码,这些代码通常会采用“复制”、“粘贴”方式来完成,通过这种复制和粘贴完成的代码在后期将很难维护:想想一下,如果有一天

SpringBoot系列之AOP实现的两种方式

大憨熊 提交于 2019-11-30 02:07:20
AOP常用的实现方式有两种, 一种是采用声明的方式来实现(基于XML),一种是采用注解的方式来实现(基于AspectJ) 。 首先复习下AOP中一些比较重要的概念: Joinpoint(连接点): 程序执行时的某个特定的点,在Spring中就是某一个方法的执行 。 Pointcut(切点): 说的通俗点,spring中AOP的切点就是指一些方法的集合,而这些方法是需要被增强、被代理的。一般都是按照一定的约定规则来表示的,如正则表达式等。切点是由一类连接点组成。 Advice(通知): 还是说的通俗点,就是在指定切点上要干些什么。 Advisor(通知器): 其实就是切点和通知的结合 。 一、基于XML配置的Spring AOP 采用声明的方式实现(在XML文件中配置),大致步骤为:配置文件中配置pointcut, 在java中用编写实际的aspect 类, 针对对切入点进行相关的业务处理。 业务接口: package com.springboottime.time.service; public interface AdviceService { /*查找用户*/ public String findUser(); /*添加用户*/ public void addUser(); } 业务实现: package com.springboottime.time.service

Pointcut matching methods with annotated parameters

天涯浪子 提交于 2019-11-30 00:23:21
I need to create an aspect with a pointcut matching a method if: Is public Its class is annotated with @Controller (Finally does not) One of its parameters (can have many) is annotated with @MyParamAnnotation. I think the first two conditions are easy, but I don't know if its possible to accomplish the third with Spring. If it is not, maybe I can change it into: One of its parameters is an instance of type com.me.MyType (or implements some interface) Do you think it's possible to achieve this? And will performance be good? Thanks EDIT : One example of a matching method. As you can see,

使用Spring进行面向切面编程(AOP)

↘锁芯ラ 提交于 2019-11-29 22:51:20
转载于 http://www.blogjava.net/supercrsky/articles/174368.html 文章太长,写的很好,没看完,转过来慢慢理解,品味 简介 面向切面编程 ( AOP )提供另外一种角度来思考程序结构,通过这种方式弥补了面向对象编程(OOP)的不足。 除了类(classes)以外,AOP提供了 切面 。切面对关注点进行模块化,例如横切多个类型和对象的事务管理。 (这些关注点术语通常称作 横切(crosscutting) 关注点。) Spring的一个关键的组件就是 AOP框架 。 尽管如此,Spring IoC容器并不依赖于AOP,这意味着你可以自由选择是否使用AOP,AOP提供强大的中间件解决方案,这使得Spring IoC容器更加完善。 Spring 2.0 AOP Spring 2.0 引入了一种更加简单并且更强大的方式来自定义切面,用户可以选择使用基于模式(schema-based)的方式或者使用@AspectJ注解。 对于新的应用程序,如果用户使用Java 5开发,我们推荐用户使用@AspectJ风格,否则可以使用基于模式的风格。 这两种风格都完全支持通知(Advice)类型和AspectJ的切入点语言,虽然实际上仍然使用Spring AOP进行织入(Weaving)。 本章主要讨论Spring 2.0对基于模式和基于

完整剖析SpringAOP的自调用

泄露秘密 提交于 2019-11-29 19:28:13
摘要 spring全家桶帮助java web开发者节省了很多开发量,提升了效率。但是因为屏蔽了很多细节,导致很多开发者只知其然,不知其所以然,本文就是分析下使用spring的一些注解,不能够自调用的问题。因为本身这类文章很多,所以有些地方不会详述,直接引用其他文章。 问题 使用了Spring中哪些注解不能进行自调用 为什么代理了就不能自调用 Spring常用的 @Cache , @Async , @Transaction 这三种原理上有什么区别吗 如何解自调用的问题 使用不同的解法各自有什么坑 AOP的概述 首先需要澄清几个需要区分的名词 AOP Spring AOP AspectJ AOP Aspect-oriented programming,面向切面编程,一种解决问题的思想,将一些重复性的编码问题通过切面来实现。 很多人了解切面是通过Spring来了解的,所以会有种误解将SpringAOP和AOP划等号,其实不然。 Spring AOP Spring AOP 算是 一种简单的 AOP的落地实现方式,它主要提供在Spring容器内的一种AOP实现方式,脱离了Spring就不work了。Spring AOP并不是一套完整的AOP解决方案。 Spring的的众多组件都是这样,Spring-Session,Spring-jdbc,Spring-Cache等等,都能解决一部分通用的需求

How do you configure aspectj maven plugin to use Java 7?

柔情痞子 提交于 2019-11-29 19:17:37
问题 What are the appropriate configuration/versions/plugin versions for the aspectj plugin to use Java 7? I am trying to upgrade from Java 6 to Java 7, and the aspectj compiler seems to not be compiling Java 7. I'm specifying the java source and target version as 1.7 in the plugin configuration for aspectj plugin and for the maven compiler plugin. I introduced Java7-specific syntax to my code, adding several language features such as string in switch and the diamond operator. During the build, I