File tree Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change
1
+ package hello .aop .exam ;
2
+
3
+ import org .springframework .stereotype .Repository ;
4
+
5
+ @ Repository
6
+ public class ExamRepository {
7
+
8
+ private static int seq = 0 ;
9
+
10
+ /**
11
+ * 5번에 1번 실패하는 요청
12
+ * 실패할 때 AOP로 복구하도록 설정
13
+ */
14
+ public String save (String itemId ) {
15
+ seq ++;
16
+ if (seq % 5 == 0 ) {
17
+ throw new IllegalStateException ("예외 발생" );
18
+ }
19
+ return "ok" ;
20
+ }
21
+ }
Original file line number Diff line number Diff line change
1
+ package hello .aop .exam ;
2
+
3
+ import lombok .RequiredArgsConstructor ;
4
+ import org .springframework .stereotype .Service ;
5
+
6
+ @ Service
7
+ @ RequiredArgsConstructor
8
+ public class ExamService {
9
+
10
+ private final ExamRepository examRepository ;
11
+
12
+ public void request (String itemId ) {
13
+ examRepository .save (itemId );
14
+ }
15
+ }
Original file line number Diff line number Diff line change
1
+ package hello .aop .exam ;
2
+
3
+ import lombok .extern .slf4j .Slf4j ;
4
+ import org .junit .jupiter .api .Test ;
5
+ import org .springframework .beans .factory .annotation .Autowired ;
6
+ import org .springframework .boot .test .context .SpringBootTest ;
7
+
8
+ @ Slf4j
9
+ @ SpringBootTest
10
+ public class ExamTest {
11
+
12
+ @ Autowired
13
+ ExamService examService ;
14
+
15
+ @ Test
16
+ void test () {
17
+ for (int i = 0 ; i < 5 ; i ++) {
18
+ log .info ("client request i={}" , i );
19
+ examService .request ("data" + i );
20
+ }
21
+ }
22
+ }
You can’t perform that action at this time.
0 commit comments