spring-aop

Logging elapsed time of execution in SpringBoot rest API

不想你离开。 提交于 2020-07-23 09:02:06
问题 It could be a simple solution but I am unable to get it done. I need to log the overall execution time for my request in SpringBoot Rest API. Request always enters to MainController always and can exit from two places- Main Restcontroller same method or ExceptionHandlerController handler method I have created one custom annotation and injecting it to both main Controller and ExceptionController methods and getting elapsed time for individual methods. So here is the problem. I need to add

Spring AOP @Around access the value of @annotation

匆匆过客 提交于 2020-07-09 07:30:48
问题 I have a custom annotation as, @Target({ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) public @interface XAudit { AuditActionType action(); } I am using this annotation on some method as following, @XAudit(action = "REGISTRATION") public RegistrationDTO register(UserDetail detail) { //Logic return dto; } I am capturing event in aspect as following, @Around(value = "@annotation(XAudit)") public Object postAuditEvent(ProceedingJoinPoint joinPoint, XAudit xAudit) throws Throwable {

Spring AOP works without @EnableAspectJAutoProxy?

不问归期 提交于 2020-06-13 17:57:47
问题 I am learning Spring (currently its AOP framework). Even though all sources I've read say that to enable AOP one needs to use @EnableAspectJAutoProxy annotation (or its XML counterpart) my code seems to work with annotation commented out. Is that because I use Lombok or Spring Boot (v. 1.5.9.RELEASE, dependent on Spring v. 4.3.13.RELEASE)? Minimal example follows: build.gradle buildscript { ext { springBootVersion = '1.5.9.RELEASE' } repositories { mavenCentral() } dependencies { classpath(

Spring AOP works without @EnableAspectJAutoProxy?

Deadly 提交于 2020-06-13 17:57:05
问题 I am learning Spring (currently its AOP framework). Even though all sources I've read say that to enable AOP one needs to use @EnableAspectJAutoProxy annotation (or its XML counterpart) my code seems to work with annotation commented out. Is that because I use Lombok or Spring Boot (v. 1.5.9.RELEASE, dependent on Spring v. 4.3.13.RELEASE)? Minimal example follows: build.gradle buildscript { ext { springBootVersion = '1.5.9.RELEASE' } repositories { mavenCentral() } dependencies { classpath(

Java aop ComponentScan not working & AnnotationConfigApplicationContext getBean not working

醉酒当歌 提交于 2020-06-08 12:14:28
问题 I wrote a simple set of classes to show a friend about using Annotations for AOP (instead of xml config) . We couldnt get the @ComponentScan to work AND AnnotationConfigApplicationContext getBean too misbehaves. I wanted to understand two things . See Code below : PersonOperationsI.java package samples.chapter3; import org.springframework.stereotype.Component; @Component public interface PersonOperationsI { public String getName(); } PersonOperations.java /** * */ package samples.chapter3;

Difference between @target and @within (Spring AOP)

只愿长相守 提交于 2020-05-25 07:24:47
问题 Spring manual says: any join point (method execution only in Spring AOP) where the target object has an @Transactional annotation: @target(org.springframework.transaction.annotation .Transactional) any join point (method execution only in Spring AOP) where the declared type of the target object has an @Transactional annotation: @within(org.springframework.transaction.annotation .Transactional) But I not see any difference between them! I tried to Google it: One difference between the two is

Difference between @target and @within (Spring AOP)

北慕城南 提交于 2020-05-25 07:24:05
问题 Spring manual says: any join point (method execution only in Spring AOP) where the target object has an @Transactional annotation: @target(org.springframework.transaction.annotation .Transactional) any join point (method execution only in Spring AOP) where the declared type of the target object has an @Transactional annotation: @within(org.springframework.transaction.annotation .Transactional) But I not see any difference between them! I tried to Google it: One difference between the two is

spring creates proxy for wrong classes when using aop class level annotation

社会主义新天地 提交于 2020-05-20 23:06:42
问题 When using spring AOP with class level annotations, spring context.getBean seems to always create and return a proxy or interceptor for every class, wether they have the annotation or not. This behavior is only for class level annotation. For method level annotations, or execution pointcuts, if there is no need for interception, getBean returns a POJO. Is this a bug? As designed? Or am i doing something wrong? @Component @Aspect public class AspectA { @Around("@target(myAnnotation)") public

Spring aop is not getting triggerd for external jar method in spring boot application

大憨熊 提交于 2020-05-17 08:04:18
问题 I am trying to have point cut for a method in jar and it is not getting triggered properly I have my rest endpoint code as below : package com.example.log.javatpoint; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation

Spring AOP around controllers does not work when request input are invalid

狂风中的少年 提交于 2020-04-30 10:28:32
问题 I have written a request/response logger using @Around : @Around(value = "execution(* com.xyz.example.controller.*.*(..))") public Object logControllers(ProceedingJoinPoint joinPoint) throws Throwable { Object response = joinPoint.proceed(); // Log request and response return response; } However, I realized if the request input (ie. request body) provided are invalid, for example, if number is a required field in the request body, and it must be an Integer , but I entered a String as its