aop

Inheriting annotation for AOP in GUICE

扶醉桌前 提交于 2021-01-28 13:34:22
问题 I'm using Guice and AspectJ, and I am trying to do some AOP to measure the execution time of certain methods. I have this annotation which will be used to annotate all the methods I need to measure: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) @Inherited public @interface MyStopWatch { } I have this method interceptor: public class MyInterceptor implements org.aopalliance.intercept.MethodInterceptor { private final Logger logger = LoggerFactory.getLogger(MyInterceptor.class

Handling void methods in assignment from proceed() in AOP using AspectJ

大兔子大兔子 提交于 2021-01-28 11:49:16
问题 I am writing a very generic code to capture the return type using around as result = proceed(); followed by return result; . Some methods are of type void . E.g. void doPrint() { System.out.println("Doing something"); } How can these methods of return type void be handled in a generic way along with methods returning a value or throwing an exception? The code I have so far is: import java.util.Arrays; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import

How i can change method annotations value in RunTime?

末鹿安然 提交于 2021-01-28 07:50:25
问题 I have controller like @MessageMapping("/room.register") @SendTo("#{sendTo}") public Message addUser(@Payload Message message, SimpMessageHeaderAccessor headerAccessor) { headerAccessor.getSessionAttributes().put("username", message.getSender()); return message; } And i want to change value of SendTo annotation in runtime. I tried to do it as follows: @Aspect public class SendToAspect { @Autowired private WebSocketConfigurationProperties webSocketConfigurationProperties; @Around("execution

AOP around overridden methods of external library?

一笑奈何 提交于 2021-01-27 13:22:27
问题 I am searching for a practical solution for the following problem: An external library provides components as base classes. Custom components are made by extending those base classes. The base classes break when the implementations throw unhandled exceptions. The base classes source code is not available. Only a binary jar. What I am looking for is to have a generic AOP error handling advice. It would wrap the code of every method that is a direct override or implementation of a method from

org.hibernate.HibernateException: No CurrentSessionContext configured

爷,独闯天下 提交于 2021-01-27 06:32:00
问题 Iam using Spring Transactional and AspectJ in my web application. application-context.xml <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http:/

org.hibernate.HibernateException: No CurrentSessionContext configured

别等时光非礼了梦想. 提交于 2021-01-27 06:31:59
问题 Iam using Spring Transactional and AspectJ in my web application. application-context.xml <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http:/

AOP 那点事儿

旧街凉风 提交于 2021-01-14 01:03:55
今天我要和大家分享的是 AOP(Aspect-Oriented Programming)这个东西,名字与 OOP 仅差一个字母,其实它是对 OOP 编程方式的一种补充,并非是取而代之。翻译过来就是“面向方面编程”,可我更倾向于翻译为“面向切面编程”。 它听起有些的神秘, 为什么呢?当你看完这篇文章的时候,就就知道,我们做的很重要的工作就是去写这个“切面” 。那么什么是“切面”呢? 没错!就是用一把刀来切一坨面。注意,相对于面而言,我们一定是横着来切它,这简称为“横切”。可以把一段代码想象成一坨面,同样也可以用一把刀来横切它,下面要做的就是如何去实现这把刀! 需要澄清的是,这个概念不是由 Rod Johnson(老罗)提出的。其实很早以前就有了,目前最知名最强大的 Java 开源项目就是 AspectJ 了,然而它的前身是 AspectWerkz(该项目已经在 2005 年停止更新),这才是 AOP 的老祖宗。老罗(一个头发秃得和我老爸有一拼的天才)写了一个叫做 Spring 框架,从此一炮走红,成为了 Spring 之父。他在自己的 IOC 的基础之上,又实现了一套 AOP 的框架,后来仿佛发现自己越来越走进深渊里,在不能自拔的时候,有人建议他还是集成 AspectJ 吧,他在万般无奈之下才接受了该建议。于是,我们现在用得最多的想必就是 Spring + AspectJ 这种

AOP: error at ::0 inconsistent binding applying aop on two different methods

帅比萌擦擦* 提交于 2021-01-08 02:09:57
问题 I am trying to apply a @before aspect on two different methods in two different paths class Service1{ public Object applyX(X x){ //code } } class Service2{ public OtherObject applyY(Y y){ //code } } and I have my aspect class: @Aspect @Component public class MyProcessor { @Before("execution(* com.a.b.c.Service1.applyX" + " (com.xp.X)) " + "&& args(engineEvaluationRequest) || " + "execution(* com.a.b.d.Service2.applyY" + " (com.yp.Y))" + "&& args(y)") public void process(X x ,Y y){ //code } }

AOP: error at ::0 inconsistent binding applying aop on two different methods

空扰寡人 提交于 2021-01-08 02:02:37
问题 I am trying to apply a @before aspect on two different methods in two different paths class Service1{ public Object applyX(X x){ //code } } class Service2{ public OtherObject applyY(Y y){ //code } } and I have my aspect class: @Aspect @Component public class MyProcessor { @Before("execution(* com.a.b.c.Service1.applyX" + " (com.xp.X)) " + "&& args(engineEvaluationRequest) || " + "execution(* com.a.b.d.Service2.applyY" + " (com.yp.Y))" + "&& args(y)") public void process(X x ,Y y){ //code } }

How @Aspect with @Component annotation works under the hood

邮差的信 提交于 2021-01-05 06:04:28
问题 I've been looking for an answer for a while, but no luck so far, thus I'm coming here for some words of wisdom. I've created an aspect using @Aspect annotation, because I need to @Autowire some singleton dependencies I've decided to annotate this aspect class with @Component and let the Spring to do the magic. It works, however ... I'm fairly familiar with AOP concept, what's weaving and different flavors of it (cglib vs aspectj) but it's not fully intuitive to me how it works under the hood.