diff --git a/cdi/src/main/java/com/baeldung/interceptor/Audited.java b/cdi/src/main/java/com/baeldung/interceptor/Audited.java index 4065450b09..3df4bef95e 100644 --- a/cdi/src/main/java/com/baeldung/interceptor/Audited.java +++ b/cdi/src/main/java/com/baeldung/interceptor/Audited.java @@ -1,12 +1,14 @@ package com.baeldung.interceptor; -import javax.interceptor.InterceptorBinding; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import javax.interceptor.InterceptorBinding; + @InterceptorBinding -@Target( {ElementType.METHOD, ElementType.TYPE } ) -@Retention(RetentionPolicy.RUNTIME ) -public @interface Audited {} +@Target({ ElementType.METHOD, ElementType.TYPE }) +@Retention(RetentionPolicy.RUNTIME) +public @interface Audited { +} diff --git a/cdi/src/main/java/com/baeldung/interceptor/AuditedInterceptor.java b/cdi/src/main/java/com/baeldung/interceptor/AuditedInterceptor.java index 46ab9b33c8..c62d9a4127 100644 --- a/cdi/src/main/java/com/baeldung/interceptor/AuditedInterceptor.java +++ b/cdi/src/main/java/com/baeldung/interceptor/AuditedInterceptor.java @@ -3,12 +3,13 @@ package com.baeldung.interceptor; import javax.interceptor.AroundInvoke; import javax.interceptor.Interceptor; import javax.interceptor.InvocationContext; -import java.lang.reflect.Method; -@Audited @Interceptor +@Audited +@Interceptor public class AuditedInterceptor { public static boolean calledBefore = false; public static boolean calledAfter = false; + @AroundInvoke public Object auditMethod(InvocationContext ctx) throws Exception { calledBefore = true; diff --git a/cdi/src/main/java/com/baeldung/service/SuperService.java b/cdi/src/main/java/com/baeldung/service/SuperService.java index e1e57a4e0d..e15f049342 100644 --- a/cdi/src/main/java/com/baeldung/service/SuperService.java +++ b/cdi/src/main/java/com/baeldung/service/SuperService.java @@ -5,6 +5,6 @@ import com.baeldung.interceptor.Audited; public class SuperService { @Audited public String deliverService(String uid) { - return uid; + return uid; } } diff --git a/cdi/src/main/java/com/baeldung/spring/aspect/SpringTestAspect.java b/cdi/src/main/java/com/baeldung/spring/aspect/SpringTestAspect.java index 5d7b064d71..e48039706d 100644 --- a/cdi/src/main/java/com/baeldung/spring/aspect/SpringTestAspect.java +++ b/cdi/src/main/java/com/baeldung/spring/aspect/SpringTestAspect.java @@ -1,15 +1,12 @@ package com.baeldung.spring.aspect; -import org.aspectj.lang.JoinPoint; +import java.util.List; + import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.annotation.Before; import org.springframework.beans.factory.annotation.Autowired; -import javax.inject.Inject; -import java.util.List; - @Aspect public class SpringTestAspect { @Autowired @@ -18,9 +15,9 @@ public class SpringTestAspect { @Around("execution(* com.baeldung.spring.service.SpringSuperService.*(..))") public Object auditMethod(ProceedingJoinPoint jp) throws Throwable { String methodName = jp.getSignature().getName(); - accumulator.add("Call to "+methodName); + accumulator.add("Call to " + methodName); Object obj = jp.proceed(); - accumulator.add("Method called successfully: "+methodName); + accumulator.add("Method called successfully: " + methodName); return obj; } } diff --git a/cdi/src/main/java/com/baeldung/spring/configuration/AppConfig.java b/cdi/src/main/java/com/baeldung/spring/configuration/AppConfig.java index 6cfc8f8743..b30c4a1326 100644 --- a/cdi/src/main/java/com/baeldung/spring/configuration/AppConfig.java +++ b/cdi/src/main/java/com/baeldung/spring/configuration/AppConfig.java @@ -1,13 +1,14 @@ package com.baeldung.spring.configuration; -import com.baeldung.spring.aspect.SpringTestAspect; -import com.baeldung.spring.service.SpringSuperService; +import java.util.ArrayList; +import java.util.List; + import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableAspectJAutoProxy; -import java.util.ArrayList; -import java.util.List; +import com.baeldung.spring.aspect.SpringTestAspect; +import com.baeldung.spring.service.SpringSuperService; @Configuration @EnableAspectJAutoProxy @@ -18,12 +19,12 @@ public class AppConfig { } @Bean - public SpringTestAspect springTestAspect(){ + public SpringTestAspect springTestAspect() { return new SpringTestAspect(); } @Bean - public List getAccumulator(){ + public List getAccumulator() { return new ArrayList(); } } diff --git a/cdi/src/main/java/com/baeldung/spring/service/SpringSuperService.java b/cdi/src/main/java/com/baeldung/spring/service/SpringSuperService.java index 72dbd1c006..082eb2e0f8 100644 --- a/cdi/src/main/java/com/baeldung/spring/service/SpringSuperService.java +++ b/cdi/src/main/java/com/baeldung/spring/service/SpringSuperService.java @@ -1,7 +1,7 @@ package com.baeldung.spring.service; public class SpringSuperService { - public String getInfoFromService(String code){ + public String getInfoFromService(String code) { return code; } }