Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- kotlin
- Greedy
- java
- Proxy
- Thymeleaf
- 자바
- spring
- 스프링
- springdatajpa
- 스프링 핵심 기능
- transaction
- 알고리즘
- http
- AOP
- JPQL
- QueryDSL
- Exception
- Spring Boot
- pointcut
- 백준
- Android
- Servlet
- 김영한
- 인프런
- SpringBoot
- db
- jpa
- 그리디
- 스프링 핵심 원리
- JDBC
Archives
- Today
- Total
개발자되기 프로젝트
Proxy Pattern - V3 본문
- v3 - 컴포넌트 스캔으로 스프링 빈 자동 등록
- 이번에는 컴포넌트 스캔으로 스프링 빈을 자동 등록해보자.
1. OrderRepositoryV3
@Repository
public class OrderRepositoryV3 {
public void save(String itemId) {
if(itemId.equals("ex")){
throw new IllegalStateException("예외 발생");
}
sleep(1000);
}
private void sleep(int millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
2. OrderServiceV3
@Service
public class OrderServiceV3 {
private final OrderRepositoryV3 orderRepository;
public OrderServiceV3(OrderRepositoryV3 orderRepository) {
this.orderRepository = orderRepository;
}
public void orderItem(String itemId) {
orderRepository.save(itemId);
}
}
3. OrderControllerV3
@Slf4j
@RestController
public class OrderControllerV3 {
private final OrderServiceV3 orderService;
public OrderControllerV3(OrderServiceV3 orderService) {
this.orderService = orderService;
}
@GetMapping("/v3/request")
public String request(String itemId) {
orderService.orderItem(itemId);
return "ok";
}
@GetMapping("/v3/no-log")
public String noLog() {
return "ok";
}
}
준비 끝!
4. GitHub : 211123 Proxy 3
GitHub - bsh6463/Spring_Advanced_2
Contribute to bsh6463/Spring_Advanced_2 development by creating an account on GitHub.
github.com
'인프런 > [인프런] 스프링 핵심 원리 - 고급' 카테고리의 다른 글
Proxy, Proxy Pattern, Decorator Pattern (0) | 2021.11.23 |
---|---|
요구사항 추가 (0) | 2021.11.23 |
Proxy Pattern - V2 (0) | 2021.11.23 |
Proxy Pattern - V1 (0) | 2021.11.23 |
정리 및 한계 (0) | 2021.11.23 |
Comments