spring core aop : spring aop exam init

This commit is contained in:
haerong22
2021-11-27 22:21:24 +09:00
parent 55a837fc5f
commit f691f3b2bd
3 changed files with 57 additions and 0 deletions

View File

@@ -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";
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}
}