aspectj

Spring AOP not working when using as a compiled jar in a different project

依然范特西╮ 提交于 2021-02-07 20:52:21
问题 I have a working AOP (when using inside the project it is written in) but when I build this project (maven install), and use that JAR in another project, and try to use the @TimedLog annotation, nothing happens. I try to breakpoint into it, but it doesn't reach there. It looks like this: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface TimedLog { boolean shouldAttachMethodArgs() default false; boolean shouldAttachReturnValue() default false; String message()

Mock ProceedingJoinPoint Signature

↘锁芯ラ 提交于 2021-02-07 06:46:15
问题 I am trying to mock a ProceedingJoinPoint class and I am having difficulty mocking a method. Here is the code that is calling the mock class: ... // ProceedingJoinPoint joinPoint Object targetObject = joinPoint.getTarget(); try { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Method method = signature.getMethod(); ... ... and here is my mocked class attempt so far... accountService = new AccountService(); ProceedingJoinPoint joinPoint = mock(ProceedingJoinPoint.class)

Getting the java.lang.reflect.Method from a ProceedingJoinPoint?

怎甘沉沦 提交于 2021-02-05 13:37:29
问题 The question is short and simple: Is there a way to get the Method object from an apsectj ProceedingJoinPoint? Currently I am doing Class[] parameterTypes = new Class[joinPoint.getArgs().length]; Object[] args = joinPoint.getArgs(); for(int i=0; i<args.length; i++) { if(args[i] != null) { parameterTypes[i] = args[i].getClass(); } else { parameterTypes[i] = null; } } String methodName = joinPoint.getSignature().getName(); Method method = joinPoint.getSignature() .getDeclaringType().getMethod

Getting the java.lang.reflect.Method from a ProceedingJoinPoint?

回眸只為那壹抹淺笑 提交于 2021-02-05 13:37:21
问题 The question is short and simple: Is there a way to get the Method object from an apsectj ProceedingJoinPoint? Currently I am doing Class[] parameterTypes = new Class[joinPoint.getArgs().length]; Object[] args = joinPoint.getArgs(); for(int i=0; i<args.length; i++) { if(args[i] != null) { parameterTypes[i] = args[i].getClass(); } else { parameterTypes[i] = null; } } String methodName = joinPoint.getSignature().getName(); Method method = joinPoint.getSignature() .getDeclaringType().getMethod

AspectJ OR Operator Doesn't Seem to be Functioning

谁说我不能喝 提交于 2021-02-05 11:43:41
问题 I'm having a little trouble getting a logging aspect set up using SpringAOP + AspectJ. I would like an "Around" method to fire when either a class or method is annotated with the @Loggable annotation. Below is my advice code: @Around(value = "execution( * *(..)) && target(bean) && @annotation(loggable)", argnames "bean, loggable") public void test1(ProceedingJoinPoint method, Object bean, Loggable loggable) { } @Around(value = "execution( * *(..)) && target(bean) && @within(loggable)",

Aspectj exceptions handling on multiple matching advices

北慕城南 提交于 2021-02-05 10:39:14
问题 I have 2 aspects that are applied on the same method. When the method executes correctly I have no problem, everything is working fine and both aspects work as expected. The problem is when the method throw an exception. In these cases, the first aspect re-throw correctly the exception, but the second aspect is generating a nullpointerexception. I was able to reproduce the problem isolating the case on a unit test in a separated project. Those are the aspects (actually I removed all the logic

Aspectj exceptions handling on multiple matching advices

Deadly 提交于 2021-02-05 10:39:05
问题 I have 2 aspects that are applied on the same method. When the method executes correctly I have no problem, everything is working fine and both aspects work as expected. The problem is when the method throw an exception. In these cases, the first aspect re-throw correctly the exception, but the second aspect is generating a nullpointerexception. I was able to reproduce the problem isolating the case on a unit test in a separated project. Those are the aspects (actually I removed all the logic

Can a method call be instrumented with ByteBuddy instead of the called method?

雨燕双飞 提交于 2021-02-04 14:19:45
问题 I would like to replace some AspectJ code that protects calls to java.lang.System from some user code. java.lang.System cannot/should not be instrumented. With AspectJ the solution is to instrument the calling code like the following example. The code that should be guarded will be instrumented while the code that is allowed is not. @Around("call(public long java.lang.System.currentTimeMillis()) && within(io.someuserdomain..*) && !within(io.someotherdomain..*)) def

Can a method call be instrumented with ByteBuddy instead of the called method?

守給你的承諾、 提交于 2021-02-04 14:19:29
问题 I would like to replace some AspectJ code that protects calls to java.lang.System from some user code. java.lang.System cannot/should not be instrumented. With AspectJ the solution is to instrument the calling code like the following example. The code that should be guarded will be instrumented while the code that is allowed is not. @Around("call(public long java.lang.System.currentTimeMillis()) && within(io.someuserdomain..*) && !within(io.someotherdomain..*)) def

Spring Boot实践——Spring AOP实现之动态代理

邮差的信 提交于 2021-02-01 06:53:56
Spring AOP 介绍   AOP的介绍可以查看 Spring Boot实践——AOP实现   与AspectJ的静态代理不同,Spring AOP使用的动态代理,所谓的动态代理就是说AOP框架不会去修改字节码,而是在内存中临时为方法生成一个AOP对象,这个AOP对象包含了目标对象的全部方法,并且在特定的切点做了增强处理,并回调原对象的方法。   Spring AOP中的动态代理主要有两种方式,JDK动态代理和CGLIB动态代理。JDK动态代理通过反射来接收被代理的类,并且要求被代理的类必须实现一个接口。JDK动态代理的核心是 InvocationHandler 接口和 Proxy 类。   如果目标类没有实现接口,那么Spring AOP会选择使用CGLIB来动态代理目标类。CGLIB(Code Generation Library),是一个代码生成的类库,是利用asm开源包, 可以在运行时动态的生成某个类的子类 。注意,CGLIB是通过继承的方式做的动态代理,因此如果某个类被标记为 final ,那么它是无法使用CGLIB做动态代理的。   这里有注意的几点如下: 从Spring 3.2以后不再将CGLIB放在项目的classpath下,而是将CGLIB类打包放在spring-core下面的org.springframework中