-
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.
섹션4: 프록시 패턴과 데코레이터 패턴
- Loading branch information
Showing
8 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
6 changes: 5 additions & 1 deletion
6
스프링 로드맵5 고급편/proxy/src/main/java/hello/proxy/ProxyApplication.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
17 changes: 17 additions & 0 deletions
17
스프링 로드맵5 고급편/proxy/src/main/java/hello/proxy/app/v1/OrderControllerV1.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,17 @@ | ||
package hello.proxy.app.v1; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
|
||
@RequestMapping // Spring은 @Controller 또는 @RequestMapping이 있어야 스프링 컨트롤러로 인식 | ||
@ResponseBody | ||
public interface OrderControllerV1 { | ||
|
||
@GetMapping("/v1/request") | ||
String request(@RequestParam("itemId") String itemId); | ||
|
||
@GetMapping("/v1/no-log") | ||
String noLog(); | ||
} |
20 changes: 20 additions & 0 deletions
20
스프링 로드맵5 고급편/proxy/src/main/java/hello/proxy/app/v1/OrderControllerV1Impl.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,20 @@ | ||
package hello.proxy.app.v1; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class OrderControllerV1Impl implements OrderControllerV1 { | ||
|
||
private final OrderServiceV1 orderService; | ||
|
||
@Override | ||
public String request(final String itemId) { | ||
orderService.orderItem(itemId); | ||
return "ok"; | ||
} | ||
|
||
@Override | ||
public String noLog() { | ||
return "noLog"; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
스프링 로드맵5 고급편/proxy/src/main/java/hello/proxy/app/v1/OrderRepositoryV1.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,5 @@ | ||
package hello.proxy.app.v1; | ||
|
||
public interface OrderRepositoryV1 { | ||
void save(String itemId); | ||
} |
20 changes: 20 additions & 0 deletions
20
스프링 로드맵5 고급편/proxy/src/main/java/hello/proxy/app/v1/OrderRepositoryV1Impl.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,20 @@ | ||
package hello.proxy.app.v1; | ||
|
||
public class OrderRepositoryV1Impl implements OrderRepositoryV1 { | ||
@Override | ||
public void save(final String itemId) { | ||
// 저장 로직 | ||
if (itemId.equals("ex")) { | ||
throw new IllegalStateException("예외 발생"); | ||
} | ||
sleep(1000); | ||
} | ||
|
||
private void sleep(final int mills) { | ||
try { | ||
Thread.sleep(mills); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
스프링 로드맵5 고급편/proxy/src/main/java/hello/proxy/app/v1/OrderServiceV1.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,5 @@ | ||
package hello.proxy.app.v1; | ||
|
||
public interface OrderServiceV1 { | ||
void orderItem(String itemId); | ||
} |
14 changes: 14 additions & 0 deletions
14
스프링 로드맵5 고급편/proxy/src/main/java/hello/proxy/app/v1/OrderServiceV1Impl.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,14 @@ | ||
package hello.proxy.app.v1; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class OrderServiceV1Impl implements OrderServiceV1 { | ||
|
||
private final OrderRepositoryV1 orderRepository; | ||
|
||
@Override | ||
public void orderItem(final String itemId) { | ||
orderRepository.save(itemId); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
스프링 로드맵5 고급편/proxy/src/main/java/hello/proxy/config/AppV1Config.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,31 @@ | ||
package hello.proxy.config; | ||
|
||
import hello.proxy.app.v1.OrderControllerV1; | ||
import hello.proxy.app.v1.OrderControllerV1Impl; | ||
import hello.proxy.app.v1.OrderRepositoryV1; | ||
import hello.proxy.app.v1.OrderRepositoryV1Impl; | ||
import hello.proxy.app.v1.OrderServiceV1; | ||
import hello.proxy.app.v1.OrderServiceV1Impl; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class AppV1Config { | ||
|
||
/* Bean 수동 등록 */ | ||
|
||
@Bean | ||
public OrderControllerV1 orderControllerV1() { | ||
return new OrderControllerV1Impl(orderServiceV1()); | ||
} | ||
|
||
@Bean | ||
public OrderServiceV1 orderServiceV1() { | ||
return new OrderServiceV1Impl(orderRepositoryV1()); | ||
} | ||
|
||
@Bean | ||
public OrderRepositoryV1 orderRepositoryV1() { | ||
return new OrderRepositoryV1Impl(); | ||
} | ||
} |