aspectj

Spring - slf4J : how to automatically log errors and exceptions?

家住魔仙堡 提交于 2019-12-06 02:57:21
问题 We are using Spring with slf4j and hibernate, I'm trying to figure out a way to log exceptions and errors automatically (i.e without initiating an instance of the debugger in each class), so that it may catch any error or exception thrown and also get class and method name in the log, I read a very short note about using aspects & interceptors for this, so could you provide me with some detailed way to implement this, Regards, 回答1: an exception aspect could look like this: @Aspect public

Let eclipse use maven to compile/weave my code

浪尽此生 提交于 2019-12-06 02:14:22
I am using compile time weaving with aspectj to weave in Spring's transactional code so I can use @Transactional . When i run maven compile from inside Eclipse (which uses the aspectj-maven-plugin), eclipse synchronizes to the tomcat server and all goes well. But when Eclipse compiles (project->build automatically) it appears not to weave the spring transactional code and I get this error: javax.persistence.TransactionRequiredException: no transaction is in progress This is very annoying because I just want to code away and not manually call maven compile after eclipse compiles every time. Do

IDEA 10.5.2 Aspectj compiler - can't determine superclass of missing type org.springframework.transaction.interceptor.TransactionAspectSupport

断了今生、忘了曾经 提交于 2019-12-06 01:45:41
问题 Trying to make a module with spring aspects gives me: can't determine superclass of missing type org.springframework.transaction.interceptor.TransactionAspectSupport Works in other modules, what's up with this one? Missing dep? /S 回答1: You'll need to add the spring-tx dependency to clear this: http://mvnrepository.com/artifact/org.springframework/spring-tx <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring.version}</version> </dependency>

Ignoring Aspectj during junit tests

你。 提交于 2019-12-06 01:26:38
问题 Here is situation: We have class with defined aspect to it's methodA; We have JUnit test for this methodA; When I run JUnit test it activates Aspect as well. Any thoughts how to ignore Aspects during unit tests? I have separated tests for my Aspects and it works fine. So in my unit test I want to test only methodA without any attached aspects. I use spring 3.0 and its aspectj support. Thanks in advance. Regards, Max 回答1: You can disable the compile-time weaving that I assume your IDE is doing

Spring AOP and Post Construct

假装没事ソ 提交于 2019-12-06 00:14:26
I want to write the name of method which is using with @PostConstruct. But I found that AOP is unable to "Around" the PostConstruct method. Is there any way to use AOP with PostConstruct method? Give this a try. @Around("@annotation(javax.annotation.PostConstruct)") public void myAdvice(ProceedingJoinPoint jp) throws Throwable{ System.out.println("This is before " + jp.getSignature().getName() + "()"); jp.proceed(); } Additionally you need to activate compile-time weaving. I published a Demo project on github which uses maven. Clone https://github.com/jannikweichert/PostConstructAOPDemo and

Access a business method's local variable in a method which is in an ASPECT

无人久伴 提交于 2019-12-05 23:48:00
问题 I want to access a local variable from a method in a business class, in a method which is in an aspect class. For instance class BusinessClass { public void simpleTest() { ... String localString = new String( "test" ); ... } } MyAspect { log() { // I WANT TO ACCESS THE VALUE OF LOCALSTRING HERE } } I want to access localString's value in log method of MyAspect. Please let me know if there is any way to accomplish this using Spring / AspectJ. Also, is there is a way to accomplish without

Spring框架AOP学习总结(下)

冷暖自知 提交于 2019-12-05 21:55:20
目录 1、 AOP 的概述 2、 Spring 基于AspectJ 进行 AOP 的开发入门(XML 的方式): 3、Spring 基于AspectJ 进行 AOP 的开发入门(注解的方式): 4、Spring的注解的AOP的通知类型 5、Spring的注解的AOP的切入点的配置 @ 在 Spring框架学习一 中主要讲的是一些Spring的概述、Spring工厂、Spring属性注入以及IOC入门,其中最重要的是IOC,上一篇中IOC大概讲的小结一下: 然后呢这一篇中主要讲一下Spring中除了IOC之外的另一个重要的核心:AOP,在Spring中IOC也好,AOP也好,都必须会二者的XML开发以及注解开发,也就是说 IOC和AOP的XML开发以及注解开发都要掌握 1、 AOP 的概述 从专业的角度来讲(千万不要问我有多专业,度娘是我表锅不对是表嫂QAQ): 在软件业,AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术。AOP是OOP的延续,是软件开发中的一个热点,也是Spring框架中的一个重要内容,是函数式编程的一种衍生范型。利用AOP可以对业务逻辑的各个部分进行隔离,从而使得业务逻辑各部分之间的耦合度降低,提高程序的可重用性,同时提高了开发的效率。

AspectJ advice does not fire in Maven multi-module setup

♀尐吖头ヾ 提交于 2019-12-05 21:25:00
I'm trying to do AOP with Aspectj, but I don't know why is not executing my aspect, it just runs the main class. Is the first time I do this, so I might be doing something wrong. This is my code: The Aspect: @Aspect public class YourAspect { @Pointcut("@annotation(yourAnnotationVariableName)") public void annotationPointCutDefinition(YourAnnotation yourAnnotationVariableName){ } @Pointcut("execution(* *(..))") public void atExecution(){} @Around("annotationPointCutDefinition(yourAnnotationVariableName) && atExecution()") public Object aroundAdvice(ProceedingJoinPoint joinPoint, YourAnnotation

How to Autowire members reliably inside an Aspect - even after a context refresh?

淺唱寂寞╮ 提交于 2019-12-05 19:57:37
I have an AspectJ aspect in which I want to have @Autowired fields. Given that by default, the aspects are singletons created outside the Spring container, Spring does not manage any of the dependency injection for the aspect. Searching around on SO, Spring autowired bean for @Aspect aspect is null encountered the same problem, and using the @Configurable annotation on the aspect somehow magically allows Spring to do the dependency injection ( see @codebrickie response ). I'm still not entirely clear how that magic works, but it seems to work fine. My problem, now, is that if I refresh the

Spring框架AOP学习总结(下)

冷暖自知 提交于 2019-12-05 18:55:18
@[toc] 在 Spring框架学习一 中主要讲的是一些Spring的概述、Spring工厂、Spring属性注入以及IOC入门,其中最重要的是IOC,上一篇中IOC大概讲的小结一下: 然后呢这一篇中主要讲一下Spring中除了IOC之外的另一个重要的核心:AOP,在Spring中IOC也好,AOP也好,都必须会二者的XML开发以及注解开发,也就是说<font color=red> IOC和AOP的XML开发以及注解开发都要掌握 </font> 1、 AOP 的概述 从专业的角度来讲(千万不要问我有多专业,度娘是我表锅不对是表嫂QAQ): 在软件业,AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术。AOP是OOP的延续,是软件开发中的一个热点,也是Spring框架中的一个重要内容,是函数式编程的一种衍生范型。利用AOP可以对业务逻辑的各个部分进行隔离,从而使得业务逻辑各部分之间的耦合度降低,提高程序的可重用性,同时提高了开发的效率。 从通俗易懂且不失风趣的角度来讲:(来自武哥文章 谈谈Spring中的IOC和AOP概念 ) 面向切面编程的目标就是分离关注点。什么是关注点呢?就是你要做的事,就是关注点。假如你是个公子哥,没啥人生目标,天天就是衣来伸手,饭来张口,整天只知道玩一件事