File tree Expand file tree Collapse file tree 5 files changed +35
-0
lines changed Expand file tree Collapse file tree 5 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 1
1
package hello .aop .exam ;
2
2
3
+ import hello .aop .exam .annotation .Trace ;
3
4
import org .springframework .stereotype .Repository ;
4
5
5
6
@ Repository
@@ -11,6 +12,7 @@ public class ExamRepository {
11
12
* 5번에 1번 실패하는 요청
12
13
* 실패할 때 AOP로 복구하도록 설정
13
14
*/
15
+ @ Trace
14
16
public String save (String itemId ) {
15
17
seq ++;
16
18
if (seq % 5 == 0 ) {
Original file line number Diff line number Diff line change 1
1
package hello .aop .exam ;
2
2
3
+ import hello .aop .exam .annotation .Trace ;
3
4
import lombok .RequiredArgsConstructor ;
4
5
import org .springframework .stereotype .Service ;
5
6
@@ -9,6 +10,7 @@ public class ExamService {
9
10
10
11
private final ExamRepository examRepository ;
11
12
13
+ @ Trace
12
14
public void request (String itemId ) {
13
15
examRepository .save (itemId );
14
16
}
Original file line number Diff line number Diff line change
1
+ package hello .aop .exam .annotation ;
2
+
3
+ import java .lang .annotation .ElementType ;
4
+ import java .lang .annotation .Retention ;
5
+ import java .lang .annotation .RetentionPolicy ;
6
+ import java .lang .annotation .Target ;
7
+
8
+ @ Target (ElementType .METHOD )
9
+ @ Retention (RetentionPolicy .RUNTIME )
10
+ public @interface Trace {
11
+ }
Original file line number Diff line number Diff line change
1
+ package hello .aop .exam .aop ;
2
+
3
+ import lombok .extern .slf4j .Slf4j ;
4
+ import org .aspectj .lang .JoinPoint ;
5
+ import org .aspectj .lang .annotation .Aspect ;
6
+ import org .aspectj .lang .annotation .Before ;
7
+
8
+ @ Slf4j
9
+ @ Aspect
10
+ public class TraceAspect {
11
+
12
+ @ Before ("@annotation(hello.aop.exam.annotation.Trace)" )
13
+ public void doTrace (JoinPoint joinPoint ) {
14
+ Object [] args = joinPoint .getArgs (); // 넘어가는 인수 정보들
15
+ log .info ("[trace] {} args={}" , joinPoint .getSignature (), args );
16
+ }
17
+ }
Original file line number Diff line number Diff line change 1
1
package hello .aop .exam ;
2
2
3
+ import hello .aop .exam .aop .TraceAspect ;
3
4
import lombok .extern .slf4j .Slf4j ;
4
5
import org .junit .jupiter .api .Test ;
5
6
import org .springframework .beans .factory .annotation .Autowired ;
6
7
import org .springframework .boot .test .context .SpringBootTest ;
8
+ import org .springframework .context .annotation .Import ;
7
9
8
10
@ Slf4j
9
11
@ SpringBootTest
12
+ @ Import (TraceAspect .class )
10
13
public class ExamTest {
11
14
12
15
@ Autowired
You can’t perform that action at this time.
0 commit comments