spring core aop : spring aop exam init
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package com.example.aop.exam;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public class ExamRepository {
|
||||
|
||||
private static int seq = 0;
|
||||
|
||||
/**
|
||||
* 5번에 1번 실패하는 요청
|
||||
*/
|
||||
public String save(String itemId) {
|
||||
seq++;
|
||||
if (seq % 5 == 0) {
|
||||
throw new IllegalStateException("예외 발생!");
|
||||
}
|
||||
return "ok";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.example.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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.example.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user