-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
섹션12: 스프링 AOP - 실전 예제: 5번 중 1번은 실패하는 상황 세팅
- Loading branch information
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
스프링 로드맵5 고급편/aop/src/main/java/hello/aop/exam/ExamRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package hello.aop.exam; | ||
|
||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public class ExamRepository { | ||
|
||
private static int seq = 0; | ||
|
||
/** | ||
* 5번에 1번 실패하는 요청 | ||
* 실패할 때 AOP로 복구하도록 설정 | ||
*/ | ||
public String save(String itemId) { | ||
seq++; | ||
if (seq % 5 == 0) { | ||
throw new IllegalStateException("예외 발생"); | ||
} | ||
return "ok"; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
스프링 로드맵5 고급편/aop/src/main/java/hello/aop/exam/ExamService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package hello.aop.exam; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ExamService { | ||
|
||
private final ExamRepository examRepository; | ||
|
||
public void request(String itemId) { | ||
examRepository.save(itemId); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
스프링 로드맵5 고급편/aop/src/test/java/hello/aop/exam/ExamTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package hello.aop.exam; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@Slf4j | ||
@SpringBootTest | ||
public class ExamTest { | ||
|
||
@Autowired | ||
ExamService examService; | ||
|
||
@Test | ||
void test() { | ||
for (int i = 0; i < 5; i++) { | ||
log.info("client request i={}", i); | ||
examService.request("data" + i); | ||
} | ||
} | ||
} |