File tree Expand file tree Collapse file tree 6 files changed +22
-21
lines changed
cdi/src/main/java/com/baeldung Expand file tree Collapse file tree 6 files changed +22
-21
lines changed Original file line number Diff line number Diff line change 11package com .baeldung .interceptor ;
22
3- import javax .interceptor .InterceptorBinding ;
43import java .lang .annotation .ElementType ;
54import java .lang .annotation .Retention ;
65import java .lang .annotation .RetentionPolicy ;
76import java .lang .annotation .Target ;
87
8+ import javax .interceptor .InterceptorBinding ;
9+
910@ InterceptorBinding
10- @ Target ( {ElementType .METHOD , ElementType .TYPE } )
11- @ Retention (RetentionPolicy .RUNTIME )
12- public @interface Audited {}
11+ @ Target ({ ElementType .METHOD , ElementType .TYPE })
12+ @ Retention (RetentionPolicy .RUNTIME )
13+ public @interface Audited {
14+ }
Original file line number Diff line number Diff line change 33import javax .interceptor .AroundInvoke ;
44import javax .interceptor .Interceptor ;
55import javax .interceptor .InvocationContext ;
6- import java .lang .reflect .Method ;
76
8- @ Audited @ Interceptor
7+ @ Audited
8+ @ Interceptor
99public class AuditedInterceptor {
1010 public static boolean calledBefore = false ;
1111 public static boolean calledAfter = false ;
12+
1213 @ AroundInvoke
1314 public Object auditMethod (InvocationContext ctx ) throws Exception {
1415 calledBefore = true ;
Original file line number Diff line number Diff line change 55public class SuperService {
66 @ Audited
77 public String deliverService (String uid ) {
8- return uid ;
8+ return uid ;
99 }
1010}
Original file line number Diff line number Diff line change 11package com .baeldung .spring .aspect ;
22
3- import org .aspectj .lang .JoinPoint ;
3+ import java .util .List ;
4+
45import org .aspectj .lang .ProceedingJoinPoint ;
56import org .aspectj .lang .annotation .Around ;
67import org .aspectj .lang .annotation .Aspect ;
7- import org .aspectj .lang .annotation .Before ;
88import org .springframework .beans .factory .annotation .Autowired ;
99
10- import javax .inject .Inject ;
11- import java .util .List ;
12-
1310@ Aspect
1411public class SpringTestAspect {
1512 @ Autowired
@@ -18,9 +15,9 @@ public class SpringTestAspect {
1815 @ Around ("execution(* com.baeldung.spring.service.SpringSuperService.*(..))" )
1916 public Object auditMethod (ProceedingJoinPoint jp ) throws Throwable {
2017 String methodName = jp .getSignature ().getName ();
21- accumulator .add ("Call to " + methodName );
18+ accumulator .add ("Call to " + methodName );
2219 Object obj = jp .proceed ();
23- accumulator .add ("Method called successfully: " + methodName );
20+ accumulator .add ("Method called successfully: " + methodName );
2421 return obj ;
2522 }
2623}
Original file line number Diff line number Diff line change 11package com .baeldung .spring .configuration ;
22
3- import com .baeldung .spring .aspect .SpringTestAspect ;
4- import com .baeldung .spring .service .SpringSuperService ;
3+ import java .util .ArrayList ;
4+ import java .util .List ;
5+
56import org .springframework .context .annotation .Bean ;
67import org .springframework .context .annotation .Configuration ;
78import org .springframework .context .annotation .EnableAspectJAutoProxy ;
89
9- import java . util . ArrayList ;
10- import java . util . List ;
10+ import com . baeldung . spring . aspect . SpringTestAspect ;
11+ import com . baeldung . spring . service . SpringSuperService ;
1112
1213@ Configuration
1314@ EnableAspectJAutoProxy
@@ -18,12 +19,12 @@ public SpringSuperService springSuperService() {
1819 }
1920
2021 @ Bean
21- public SpringTestAspect springTestAspect (){
22+ public SpringTestAspect springTestAspect () {
2223 return new SpringTestAspect ();
2324 }
2425
2526 @ Bean
26- public List <String > getAccumulator (){
27+ public List <String > getAccumulator () {
2728 return new ArrayList <String >();
2829 }
2930}
Original file line number Diff line number Diff line change 11package com .baeldung .spring .service ;
22
33public class SpringSuperService {
4- public String getInfoFromService (String code ){
4+ public String getInfoFromService (String code ) {
55 return code ;
66 }
77}
You can’t perform that action at this time.
0 commit comments