spring-aop

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)",

No qualifying bean of type 'concert.PerformanceImp' available

无人久伴 提交于 2021-02-05 09:38:06
问题 I am still a beginner in Spring Framework so I tried to code a program about "introduction" in Spring AOP but I am facing an error while compiling. Please find below the classes in the package concert : PerformanceImp.java package concert; import org.springframework.stereotype.Component; @Component public class PerformanceImp implements Performance { public void perform() { System.out.println("This is the performance function"); } } Performance.java package concert; public interface

how to log with Spring AOP and SPring boot

心不动则不痛 提交于 2021-02-05 09:28:19
问题 i use the same class LoggingAspect as in this example tutorial https://www.javaguides.net/2019/05/spring-boot-spring-aop-logging-example-tutorial.html, but when i call a controller methode i get only those messages on console 11-05-2020 13:30:27.742 [http-nio-8080-exec-7] INFO o.a.c.c.C.[.[localhost].[/appged].log - Initializing Spring DispatcherServlet 'dispatcherServlet' 11-05-2020 13:30:27.742 [http-nio-8080-exec-7] INFO o.s.web.servlet.DispatcherServlet.initServletBean - Initializing

Get HTTP Method from a joinPoint

廉价感情. 提交于 2021-02-05 09:24:49
问题 I need to get the http method like POST/PATCH/GET/etc from a joinPoint in an aspect. @Before("isRestController()") public void handlePost(JoinPoint point) { // do something to get for example "POST" to use below handle(arg, "POST", someMethod::getBeforeActions); } From point.getThis.getClass() , I get the the controller that this call is intercepted. Then if I get the method from it and then annotations. That should be good enough right? So point.getThis().getClass().getMethod(point

Modify value from class with @AfterReturning in Spring AOP

安稳与你 提交于 2021-02-05 09:21:17
问题 How to modify value with @AfterReturning advice, it works for any object except String. I know that String is Immutability. and how to modify the string without changing returning type of saveEverything() function in AccountDAO class? here are code snippet: @Component public class AccountDAO { public String saveEverything(){ String save = "save"; return save; } } and aspect: @Aspect @Component public class AfterAdviceAspect { @AfterReturning(pointcut = "execution(* *.save*())", returning =

Modify value from class with @AfterReturning in Spring AOP

北慕城南 提交于 2021-02-05 09:19:05
问题 How to modify value with @AfterReturning advice, it works for any object except String. I know that String is Immutability. and how to modify the string without changing returning type of saveEverything() function in AccountDAO class? here are code snippet: @Component public class AccountDAO { public String saveEverything(){ String save = "save"; return save; } } and aspect: @Aspect @Component public class AfterAdviceAspect { @AfterReturning(pointcut = "execution(* *.save*())", returning =

How to create pointcut to feign client that supports interface inheritance?

天大地大妈咪最大 提交于 2021-01-29 15:54:02
问题 In a Spring Boot project I have a simple feign client @MyAnnotation @FeignClient(name="some-name", url="http://test.url") public interface MyClient { @RequestMapping(method = RequestMethod.GET, value = "/endpoint") List<Store> getSomething(); } I need to intercept all calls and for this and I'm creating a common library that can be used in different projects. To achieve it I try to use Spring AOP. I created an aspect that wraps all public methods of the object annotated with MyAnnotation

Exception in Spring AOP Itself not getting handled through RestControllerAdvice

早过忘川 提交于 2021-01-29 13:42:32
问题 I need to validate the HttpServletRequest for certain attribtues in my service layer before proceeding. I created @Before advice, Please note that AOP method throws Exception. I want exception thrown by this method should be handled by RestControllerAdvice. I can see that AOP method is being executed but DataNotValidException is not being handled by RestControllerAdvice. RestConrollerAdvice is working fine if there is any exception on the validation of other parameters or any exception in