spring-aop

How to capture Http verb and api end point using AOP in Spring Boot application

风流意气都作罢 提交于 2021-01-29 10:09:16
问题 I am planning to implement an aspect in order to capture the following values for a given rest API on successful return, in my spring boot application: api endpoint i.e. like /api/ ... Http verb. i.e. PUT/POST etc Request payload and request/query param I am doing this as follows: @Aspect public class MyAspect { private final Logger log = LoggerFactory.getLogger(this.getClass()); @Pointcut("within(com.web.rest.*)") public void applicationResourcePointcut() { } @AfterReturning(value = (

Issue with Spring AOP and Final class throwing “Could not generate CGLIB subclass”

孤街浪徒 提交于 2021-01-28 21:04:00
问题 1) Below is the small project I have where I do want logging with SpringAOP. Using spring-aop-4.1.6.RELEASE.jar and below is LoggingAspect.java with few point cuts. package com.myprj.aop.aspect; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; import

Spring - How to cache in self-invocation with aspectJ?

我的梦境 提交于 2021-01-28 11:17:33
问题 Thank you to click my question. I want to call a caching method in self-invocation, so I need to use AspectJ. (cache's config is okay) add AspectJ dependencies implementation 'org.springframework.boot:spring-boot-starter-aop' add @EnableCaching(mode = AdviceMode.ASPECTJ) to my application.java @EnableJpaAuditing @EnableCaching(mode = AdviceMode.ASPECTJ) // <-- here @SpringBootApplication public class DoctorAnswerApplication { public static void main(String[] args) { SpringApplication.run

How to specify single pointcut for all classes that extend a specific class

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-27 07:07:22
问题 I have multiple classes from different packages that extends a class Super. And i want to create an AOP pointcut around that match all the methods in all classes that extends Super. I have tried this: @Around("within(com.mypackage.that.contains.super..*)") public void aroundAllEndPoints(ProceedingJoinPoint joinPoint) throws Throwable { LOGGER.info("before Proceed "); joinPoint.proceed(); LOGGER.info("after Proceed"); } But it doesn't work. Any Suggestions? 回答1: The pointcut should be: within

How to specify single pointcut for all classes that extend a specific class

做~自己de王妃 提交于 2021-01-27 07:04:56
问题 I have multiple classes from different packages that extends a class Super. And i want to create an AOP pointcut around that match all the methods in all classes that extends Super. I have tried this: @Around("within(com.mypackage.that.contains.super..*)") public void aroundAllEndPoints(ProceedingJoinPoint joinPoint) throws Throwable { LOGGER.info("before Proceed "); joinPoint.proceed(); LOGGER.info("after Proceed"); } But it doesn't work. Any Suggestions? 回答1: The pointcut should be: within

How to specify single pointcut for all classes that extend a specific class

醉酒当歌 提交于 2021-01-27 07:00:14
问题 I have multiple classes from different packages that extends a class Super. And i want to create an AOP pointcut around that match all the methods in all classes that extends Super. I have tried this: @Around("within(com.mypackage.that.contains.super..*)") public void aroundAllEndPoints(ProceedingJoinPoint joinPoint) throws Throwable { LOGGER.info("before Proceed "); joinPoint.proceed(); LOGGER.info("after Proceed"); } But it doesn't work. Any Suggestions? 回答1: The pointcut should be: within

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 } }