ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

๐Ÿ‘€ Overview

๋‚˜๋Š” ํฌ๋ฏผ(ํฌ์žฅ์˜ ๋ฏผ์กฑ) ํ”„๋กœ์ ํŠธ์—์„œ ์‚ฌ์žฅ๋‹˜ ์„œ๋ฒ„์—์„œ ๊ฐ€๊ฒŒ ๋„๋ฉ”์ธ๊ณผ ๋ฉ”๋‰ด ๋„๋ฉ”์ธ์„ ๋งก์•˜๋‹ค.

 

ํฌ์žฅ์˜ ๋ฏผ์กฑ ํ”„๋กœ์ ํŠธ์—์„œ์˜ ํŠน์ด์ ์ด๋ผ๊ณ  ํ•œ๋‹ค๋ฉด, ๊ณ ๊ฐํŒ€๊ณผ ์‚ฌ์žฅํŒ€์ด ๊ฐ๊ฐ ์„œ๋ฒ„๋ฅผ ๋‚˜๋ˆ„๊ณ , ์„œ๋ฒ„๋ฅผ ๋‚˜๋ˆด์œผ๋‹ˆ DB ๋˜ํ•œ ๊ฐ๊ฐ ๋‚˜๋ˆ  ์ง„ํ–‰์„ ํ–ˆ๋‹ค.

๊ทธ๋žฌ๊ธฐ ๋•Œ๋ฌธ์—, ํ•ด๋‹น ์‚ฌ์žฅ ์„œ๋ฒ„์˜ DB์™€ ๊ณ ๊ฐ ์„œ๋ฒ„์˜ DB์˜ ์ •ํ•ฉ์„ฑ์„ ๋งž์ถ”๋Š” ๊ฒƒ์ด ํ•ต์‹ฌ์ด์˜€๊ณ  ํ•ญ์ƒ ์‚ฌ์žฅ ์„œ๋ฒ„์—์„œ ์ž์›์ด ์ƒ์„ฑ๋˜๊ฑฐ๋‚˜ ๋ณ€๊ฒฝ๋  ๋•Œ ๋งˆ๋‹ค ๊ณ ๊ฐํŒ€ ์„œ๋ฒ„๋กœ ์ •๋ณด๋ฅผ ์ „์†กํ•ด ์ฃผ์–ด์•ผ ํ–ˆ๋‹ค.

 

๋”ฐ๋ผ์„œ ์•„๋ž˜์™€ ๊ฐ™์ด InfoSender ๋นˆ์„ ํ†ตํ•ด์„œ RestTemplate์„ ํ†ตํ•ด ์ •๋ณด๋ฅผ ๊ณ ๊ฐํŒ€ ์„œ๋ฒ„๋กœ ์ „๋‹ฌํ–ˆ๋‹ค.

@Component
@RequiredArgsConstructor
public class InfoSender {

    private final RestTemplate restTemplate;

    private static final String URL_PREFIX = "http://52.78.144.166:8080/api/v1"; // ๊ณ ๊ฐํŒ€ url

    public void send(Store store) {
        StoreInfo body = StoreInfo.from(store);

        HttpEntity<StoreInfo> storeInfoHttpEntity = new HttpEntity<>(body);
        ResponseEntity<String> response = restTemplate.exchange(URL_PREFIX + "/stores", POST, storeInfoHttpEntity, String.class);
        validateResponse(response);
    }

    public void send(Menu menu) {
        MenuInfo body = MenuInfo.from(menu);

        HttpEntity<MenuInfo> menuInfoHttpEntity = new HttpEntity<>(body);
        ResponseEntity<String> response = restTemplate.exchange(URL_PREFIX + "/menus", POST, menuInfoHttpEntity, String.class);
        validateResponse(response);
    }

    public void send(Menu menu, OptionGroup optionGroup) {
        OptionGroupInfoToSend body = OptionGroupInfoToSend.from(optionGroup, menu);
        
        HttpEntity<OptionGroupInfoToSend> optionGroupInfoToSendHttpEntity = new HttpEntity<>(body);
        ResponseEntity<String> response = restTemplate.exchange(URL_PREFIX + "/options", POST, optionGroupInfoToSendHttpEntity, String.class);
        validateResponse(response);
    }

 

๊ทธ๋ฆฌ๊ณ  ํ•ด๋‹น ๋นˆ์„ ์ฃผ์ž… ๋ฐ›์•„์„œ Service ๋ฉ”์„œ๋“œ ๋งˆ๋‹ค ๋ณ€๊ฒฝ์ด ์ผ์–ด๋‚  ๋•Œ๋งˆ๋‹ค ํ•ด๋‹น ์—”ํ‹ฐํ‹ฐ ์ •๋ณด๋ฅผ ๊ณ ๊ฐํŒ€ ์„œ๋ฒ„๋กœ ๋ณด๋‚ด ์ฃผ์–ด์•ผ ํ–ˆ๋Š”๋ฐ,

๊ทธ๋ ‡๋‹ค ๋ณด๋‹ˆ Cross Cutting Concern, ํšก๋‹จ ๊ด€์‹ฌ์‚ฌ๊ฐ€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ฐœ์ƒํ•˜๊ฒŒ ๋˜์—ˆ๋‹ค.

ํšก๋‹จ ๊ด€์‹ฌ์‚ฌ์˜ ๋ฐœ์ƒ..

์ด๋ ‡๊ฒŒ ๋˜๋ฉด ๋ฌธ์ œ์ ์ด

1. InfoSender ๋นˆ์„ ์˜์กดํ•˜๊ณ  ์žˆ์–ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— InfoSender์™€ StoreService ๊ฐ„์˜ ๊ฐ•ํ•œ ๊ฒฐํ•ฉ์ด ๋ฐœ์ƒํ•œ๋‹ค.

2. ๋ฉ”์„œ๋“œ๊ฐ€ ๋‘ ๊ฐ€์ง€ ์ผ์„ ํ•˜๊ณ  ์žˆ๊ณ , ์ฝ”๋“œ์˜ ์ค‘๋ณต์ด ๋ฐœ์ƒํ•œ๋‹ค.

 

์ด๋ฅผ Spring์—์„œ ์ œ๊ณตํ•˜๋Š” Spring AOP๋ฅผ ์‚ฌ์šฉํ•ด ํ•ด๊ฒฐ ํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.

 

๐ŸฅŠ AOP๋ž€?

AOP(Aspect Oriented Programming)์ด๋ž€, ๊ด€์  ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์ด๋‹ค.

Aspect๋ž€ ๋ฌด์—‡์ผ๊นŒ?

๊ทธ๊ฒƒ ์ „์— AOP๋ฅผ ํ†ตํ•ด์„œ ํšก๋‹จ ๊ด€์‹ฌ์‚ฌ๋ฅผ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ํ•˜๋Š”๋ฐ ์–ด๋–ป๊ฒŒ ๊ทธ๊ฒŒ ๊ฐ€๋Šฅํ•œ ๊ฒƒ์ผ๊นŒ?

 

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ ํฌ๊ฒŒ ํ•ต์‹ฌ ๊ธฐ๋Šฅ๊ณผ ๋ถ€๊ฐ€ ๊ธฐ๋Šฅ์œผ๋กœ ๋‚˜๋‰œ๋‹ค.

ํ•ต์‹ฌ๊ธฐ๋Šฅ์€ ํ•ด๋‹น ๊ฐ์ฒด๊ฐ€ ์ œ๊ณตํ•˜๋Š” ๊ณ ์œ ์˜ ๊ธฐ๋Šฅ์„ ๋งํ•œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ์œ„์˜ StoreService์—์„œ ํ•ต์‹ฌ ๊ธฐ๋Šฅ์€ Store์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์ €์žฅํ•˜๊ณ , ๋ณ€๊ฒฝํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

๋ถ€๊ฐ€ ๊ธฐ๋Šฅ์€ ํ•ต์‹ฌ ๊ธฐ๋Šฅ์„ ๋ณด์กฐํ•˜๊ธฐ ์œ„ํ•ด ์ œ๊ณต๋˜๋Š” ๊ธฐ๋Šฅ์œผ๋กœ ๋กœ๊ทธ ์ถ”์ , ํŠธ๋žœ์žญ์…˜์„ ์˜ˆ๋กœ ๋“ค ์ˆ˜ ์žˆ๋Š”๋ฐ, ์œ„์—์„œ ํ•ด๋‹น ๋ณ€๊ฒฝ๋œ ์—”ํ‹ฐํ‹ฐ ์ •๋ณด๋ฅผ ๊ณ ๊ฐ ์„œ๋ฒ„์— ๋ณด๋‚ด๋Š” ๊ฒƒ์„ ๋ถ€๊ฐ€ ๊ธฐ๋Šฅ์ด๋ผ๊ณ  ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

 

์ด๋ ‡๊ฒŒ ๋ถ€๊ฐ€ ๊ธฐ๋Šฅ์„ ๋ชจ๋“ˆํ™” ํ•ด์„œ ์–ด๋””์— ์ ์šฉํ• ์ง€๋ฅผ ์„ ํƒํ•˜๋Š” ๊ธฐ๋Šฅ์„ ํ•ฉํ•ด ํ•˜๋‚˜์˜ ๋ชจ๋“ˆ๋กœ ๋งŒ๋“  ๊ฒƒ์„ Aspect๋ผ๊ณ  ํ•œ๋‹ค.

 

์ด๋ ‡๊ฒŒ ๋ถ€๊ฐ€๊ธฐ๋Šฅ๊ณผ ํ•ต์‹ฌ ๊ธฐ๋Šฅ์„ ๋ถ„๋ฆฌํ•จ์œผ๋กœ์„œ AOP๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ •๋ง ๋ฉ”์„œ๋“œ๊ฐ€ ํ•˜๋‚˜์˜ ์ผ๋งŒ ํ•  ์ˆ˜ ์žˆ๋„๋ก, ๋” ๊ฐ์ฒด ์ง€ํ–ฅ์ ์œผ๋กœ ์ฝ”๋”ฉ์ด ๊ฐ€๋Šฅํ•ด์ง„๋‹ค.

 

๐ŸฅŠ Spring์—์„œ๋Š” AOP๋ฅผ ์–ด๋–ป๊ฒŒ ๊ตฌํ˜„ํ•˜๋Š”๊ฐ€?

ํšก๋‹จ๊ด€์‹ฌ์‚ฌ, cross cutting concern์„ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด์„œ AOP๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•์—๋Š” ์„ธ ๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค.

1. ์ปดํŒŒ์ผ ์‹œ์ ์— .class ํŒŒ์ผ๋กœ ๋ณ€ํ™˜ ๋ ๋•Œ ๋ฐ”์ดํŠธ์ฝ”๋“œ๋ฅผ ๋ง๋ถ™ํ˜€ AOP๋ฅผ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

2. ํด๋ž˜์Šค ๋กœ๋”์— ๋กœ๋“œ ๋  ๋•Œ ์ฝ”๋“œ๋ฅผ ๋ง๋ถ™ํ˜€ AOP๋ฅผ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

3. ๋Ÿฐํƒ€์ž„ ์‹œ์ ์— ์žˆ์–ด์„œ AOP๋ฅผ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ, ํ”„๋ก์‹œ๋ฅผ ์‚ฌ์šฉํ•ด AOP๋ฅผ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

 

์ฒซ๋ฒˆ์งธ, ๋‘ ๋ฒˆ์งธ ๋ฐฉ์‹, ์ฆ‰ ์ปดํŒŒ์ผ ์‹œ์ ๊ณผ ํด๋ž˜์Šค ๋กœ๋”์— ๋กœ๋“œ ๋˜๋Š” ์‹œ์ ์— AOP๋ฅผ ์ ์šฉํ•˜๋Š” ๋ฐฉ์‹์€ AOP์— ๋Œ€ํ•œ ๊ฑฐ์˜ ๋ชจ๋“  ๊ธฐ๋Šฅ์„ ์ง€์›ํ•˜๋Š” AspectJ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ํ†ตํ•ด ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์ง€๋งŒ, ์ƒ๋‹นํžˆ ํ•™์Šต๋Ÿ‰๋„ ๋งŽ๊ณ  ๋ณต์žกํ•˜๋‹ค๊ณ  ํ•œ๋‹ค.

๊ทธ๋ž˜์„œ Spring์—์„œ๋Š” AOP๋ฅผ ํ”„๋ก์‹œ๋ฅผ ์‚ฌ์šฉํ•ด ๋Ÿฐํƒ€์ž„์— ์ ์šฉํ•˜๋Š” ๋ฐฉ์‹์„ ํƒํ–ˆ๋‹ค.

 

๊ทธ๋Ÿผ ์Šคํ”„๋ง์—์„œ๋Š” AOP๋ฅผ ์ ์šฉํ•  ๋Œ€์ƒ์„ ํ”„๋ก์‹œ๋ฅผ ํ†ตํ•ด ์–ด๋–ป๊ฒŒ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์„๊นŒ?

์ด๊ฒƒ์— ๋Œ€ํ•ด์„œ ์„ค๋ช…ํ•˜๊ธฐ์œ„ํ•ด ๋จผ์ € ์šฉ์–ด์ •๋ฆฌ๋ฅผ ํ•˜์ž๋ฉด, AOP๋ฅผ ์ ์šฉํ•  ๋Œ€์ƒ์ธ Joinpoint, ์ ์šฉํ•  ๋ถ€๊ฐ€ ๋กœ์ง์ธ Advice, ์ ์šฉ ์œ„์น˜๋ฅผ ์„ค์ •ํ•˜๋Š” Pointcut, ํ•˜๋‚˜์˜ Advice์™€ ํ•˜๋‚˜์˜ Pointcut์„ ํ•ฉ์นœ Advisor๊ฐ€ ์žˆ๋‹ค.

Pointcut์— ํ•ด๋‹นํ•˜๋Š” ๋ฉ”์„œ๋“œ๊ฐ€ ์žˆ๋Š” ํด๋ž˜์Šค๋ฅผ ๋นˆ ๋“ฑ๋ก ์‹œ CGLIB ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•ด ๋Œ€์ƒ ๋นˆ์„ ํ”„๋ก์‹œ๋กœ ๋“ฑ๋กํ•ด Advice๋ฅผ ์ ์šฉํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ํ”„๋ก์‹œ ํŒจํ„ด์„ ํ†ตํ•ด AOP๋ฅผ ๋Ÿฐํƒ€์ž„์— ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

๊ทธ๋Ÿผ PointCut์œผ๋กœ ์„ค์ •๋œ ๋Œ€์ƒ์— Proxy์ ์šฉ์„ ์–ด๋–ป๊ฒŒ ํ•˜๋Š๋ƒ?

๋นˆ ํ›„ ์ฒ˜๋ฆฌ๊ธฐ(Bean Post Processor)๋ฅผ ํ†ตํ•ด ๋‹ค๋ฅธ ์„ค์ •์—†์ด Bean์œผ๋กœ ๋“ฑ๋ก ๋œ ๊ฒƒ์„ ํ”„๋ก์‹œ ๊ฐ์ฒด๋กœ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ๋Š”๋ฐ, @Aspect ์–ด๋…ธํ…Œ์ด์…˜์„ ์‚ฌ์šฉํ•ด Pointcut๊ณผ Advice๋ฅผ ์„ค์ •ํ•˜๋ฉด, AnnotationAwareAspectJAutoProxyCreator๊ฐ€ ์ž๋™์œผ๋กœ ํ”„๋ก์‹œ๋ฅผ ๋นˆ์œผ๋กœ ๋“ฑ๋ก ์‹œ์ผœ ์ค€๋‹ค.

 

์—ฌ๋Ÿฌ ๋ถ€๊ฐ€๊ธฐ๋Šฅ๊ณผ ์ ์šฉ์œ„์น˜ Pointcut์„ ํ•ฉ์นœ Aspect๋ฅผ ์„ค์ •ํ•˜๋ฉด, ์ž๋™์œผ๋กœ ํ”„๋ก์‹œ๋ฅผ ๋งŒ๋“ค์–ด AOP๋ฅผ ๋Ÿฐํƒ€์ž„์— ์„ค์ •ํ•ด ์ฃผ๋Š” ๊ฒƒ์ด Spring์—์„œ ์ œ๊ณตํ•˜๋Š” AOP ๊ธฐ๋Šฅ์ด๋‹ค.

 

๐ŸฅŠ AOP๋ฅผ ์ ์šฉํ•ด๋ณด์ž!

๋จผ์ €, ์ฒ˜์Œ ์œ„ StoreService์—์„œ InfoSender๋ฅผ ๋ถ„๋ฆฌํ•ด ๋ณด์ž.

๊ทธ๋Ÿฌ๊ธฐ ์œ„ํ•ด์„œ Aspect๋ฅผ ์„ค์ •ํ•ด ์ฃผ์–ด์•ผ ํ•˜๋Š”๋ฐ, Aspect์˜ Pointcut ์„ค์ •ํ•˜๋Š”๋ฐ ์žˆ์–ด ์•„๋ž˜์™€ ๊ฐ™์ด @TransmitData ์–ด๋…ธํ…Œ์ด์…˜์„ ์ƒ์„ฑํ•ด ์–ด๋…ธํ…Œ์ด์…˜ ๋Œ€์ƒ์œผ๋กœ Pointcut์„ ์„ค์ •ํ•ด ์ฃผ์—ˆ๋‹ค.

 

๊ทธ ์ด์œ ๋Š” StoreService, MenuService์— AOP๋ฅผ ์„ค์ •ํ•˜๊ณ  ์‹ถ์€๋ฐ, ๋ชจ๋“  ํด๋ž˜์Šค์˜ ๋ฉ”์„œ๋“œ์— ์ ์šฉํ•˜๋Š”๊ฒŒ ์•„๋‹ˆ๋ผ ์–ด๋–ค ๋ฉ”์„œ๋“œ๋Š” ๊ณ ๊ฐํŒ€์— ์ „์†ก๊ธฐ๋Šฅ์ด ํ•„์š”ํ•˜๊ณ , ์–ด๋–ค ๋ฉ”์„œ๋“œ๋Š” ํ•„์š” ์—†์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ์‚ฌ์šฉํ•˜๊ธฐ ๊ฐ„ํŽธํ•œ ์–ด๋…ธํ…Œ์ด์…˜ ๊ธฐ๋ฐ˜์œผ๋กœ Pointcut์„ ์„ค์ •ํ–ˆ๋‹ค.

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface TransmitData {

}

 

@Slf4j
@Aspect
@Component
@RequiredArgsConstructor
public class DataTransferAspect {

    private final InfoSender infoSender;

    @Pointcut("@annotation(com.ray.pominowner.store.service.aop.TransmitData)")
    private void toTransmitDataAnnotation() {}

    @AfterReturning(pointcut = "toTransmitDataAnnotation()", returning = "store")
    public void transmitData(Store store) {
        infoSender.send(store);
        log.info("store info sent");
    }

    @AfterReturning(pointcut = "toTransmitDataAnnotation()", returning = "menu")
    public void transmitData(Menu menu) {
        infoSender.send(menu);
        log.info("menu info sent");
    }

    @AfterReturning(pointcut = "toTransmitDataAnnotation()", returning = "optionInfo")
    public void transmitData(OptionGroupInfoToSend optionInfo) {
        infoSender.send(optionInfo);
        log.info("option info sent");
    }

}

 

โ“ ์™œ @Around ๋Œ€์‹  @AfterReturning์„ ์‚ฌ์šฉํ–ˆ๋Š”๊ฐ€?

๋˜ ์œ„์™€ ๊ฐ™์ด @Around ๋Œ€์‹  @AfterReturning์„ ์‚ฌ์šฉํ•œ ์ด์œ ๋Š”, ProceedingJoinPoint์˜ proceed() ๋ฉ”์„œ๋“œ ํ˜ธ์ถœ์„ ํ•ด์•ผํ•  ํ•„์š”์„ฑ์„ ๋ชป๋Š๊ผˆ๋˜๊ฒƒ์ด ๊ฐ€์žฅ ์ปธ๊ณ , @AfterReturning์„ ์‚ฌ์šฉํ•˜๋Š”๊ฒƒ์ด target๋ฉ”์„œ๋“œ์˜ ๋ฉ”์„œ๋“œ๊ฐ€ return๋˜๊ณ  ๋™์ž‘ํ•˜๋Š” ๊ธฐ๋Šฅ์ด๋ผ๋Š” ๊ฒƒ์ด ๋ช…ํ™•ํ•˜๊ฒŒ ๋ณด์˜€๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

๊ทธ๋ฆฌ๊ณ  return๊ฐ’์„ ์‚ฌ์šฉํ•ด ๋ฐ”๋กœ ๊ณ ๊ฐํŒ€ ์„œ๋ฒ„์— ๋ณด๋‚ด๋ฉด ๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์—, @AfterReturning์„ ์‚ฌ์šฉํ–ˆ๋‹ค.

 

โ“ ์™œ ํ•˜๋‚˜์˜ advice ๋ฉ”์„œ๋“œ์—์„œ ์ฒ˜๋ฆฌํ•œ ๊ฒŒ ์•„๋‹ˆ๋ผ ๋ฉ”์„œ๋“œ๋ฅผ ๊ฐ๊ฐ ๋งŒ๋“ค์—ˆ๋Š”๊ฐ€?

returning์—์„œ ์„ค์ •ํ•œ ๊ฐ’๊ณผ ๋™์ผํ•œ ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ์™”์„ ๋•Œ, Object๋กœ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๋ฐ›์•„ instanceof ๋ฅผ ํ†ตํ•ด ํŒจํ„ด ๋งค์นญ ํ›„ ํ•ด๋‹น ํƒ€์ž…์— ๋งž๋Š” ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค๋ฉด ๋ฉ”์„œ๋“œ ์„ธ ๊ฐœ๊ฐ€ ์•„๋‹Œ ํ•˜๋‚˜๋กœ ๋๋‚˜๋Š” ๋ฌธ์ œ์˜€๋‹ค.

๊ทธ ์ด์œ ๋Š”, ๊ฐ€๋…์„ฑ์ด ๋–จ์–ด์ง€๊ณ  ์ง€์ €๋ถ„ํ•ด์ง€๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

์ž๋ฐ” 21์˜ switch ๋ฌธ์„ ํ†ตํ•œ ํŒจํ„ด๋งค์นญ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค๋ฉด ๋ฆฌํŽ™ํ† ๋ง์„ ํ•  ์ˆ˜ ์žˆ๊ฒ ์ง€๋งŒ, ์ž๋ฐ” 17๋ฒ„์ „์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๊ธฐ๋„ ํ•˜๊ณ , @AfterReturning ์‚ฌ์šฉ์‹œ return ๊ฐ’์„ ๋ฐ›๋Š” ๊ฒƒ์— ์žˆ์–ด์„œ ํƒ€์ž…์ด ๋‹ค๋ฅด๋ฉด AOP ์ ์šฉ์ด ๋ฌด์‹œ ๋˜๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ๊ฐ ๋ฉ”์„œ๋“œ๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ์–ด ๊ฐ€๋…์„ฑ์„ ๋†’ํžˆ๊ณ  ์—ญํ• ์„ ๋ถ„๋ฆฌ ์‹œํ‚ฌ ์ˆ˜ ์žˆ์—ˆ๋‹ค.

 

์œ„์™€ ๊ฐ™์ด Aspect๋ฅผ ์„ค์ •ํ•˜๊ณ , ๋Œ€์ƒ์ด ๋˜๋Š” Service ์ฝ”๋“œ๋ฅผ ์•„๋ž˜์™€ ๊ฐ™์ด ๋ฆฌํŽ™ํ† ๋ง ํ•ด ์ฃผ์—ˆ๋‹ค.

MenuService
StoreService

๋ฌผ๋ก  Entity๋ฅผ ๋ฐ˜ํ™˜ํ•ด ์ฃผ์–ด์•ผ ํ•œ๋‹ค๋Š” ์ ์œผ๋กœ Controller์˜ ์ฝ”๋“œ๋„ ์•ฝ๊ฐ„ ์ˆ˜์ •๋˜๊ธด ํ•˜์ง€๋งŒ ํฐ ๋ฌธ์ œ๊ฐ€ ๋˜์ง„ ์•Š์•˜๋‹ค.

 

์ด๋ ‡๊ฒŒ AOP๋ฅผ ํ†ตํ•ด ํ•ต์‹ฌ ๋กœ์ง๊ณผ ๊ณตํ†ต ๋กœ์ง์„ ๋ถ„๋ฆฌ ์‹œํ‚ด์œผ๋กœ์„œ ๊ฐ์ฒด์ง€ํ–ฅ์ ์ด๊ณ  ๊ฐ€๋…์„ฑ ๋†’์€ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค!

 

Reference

https://m.yes24.com/Goods/Detail/17350624

 

์Šคํ”„๋ง ์ž…๋ฌธ์„ ์œ„ํ•œ ์ž๋ฐ” ๊ฐ์ฒด ์ง€ํ–ฅ์˜ ์›๋ฆฌ์™€ ์ดํ•ด - ์˜ˆ์Šค24

์ž๋ฐ” ์—”ํ„ฐํ”„๋ผ์ด์ฆˆ ๊ฐœ๋ฐœ์„ ํŽธํ•˜๊ฒŒ ํ•ด์ฃผ๋Š” ์˜คํ”ˆ์†Œ์Šค ๊ฒฝ๋Ÿ‰ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ”„๋ ˆ์ž„์›Œํฌ์ธ ์Šคํ”„๋ง์€ ์ž๋ฐ”์™€ ๊ฐ์ฒด ์ง€ํ–ฅ์ด๋ผ๋Š” ๊ธฐ๋ฐ˜ ์œ„์— ๊ตณ๊ฑดํžˆ ์„ธ์›Œ์ ธ ์žˆ๋‹ค. ๋”ฐ๋ผ์„œ ์Šคํ”„๋ง์„ ์ œ๋Œ€๋กœ ์ดํ•ดํ•˜๊ณ  ํ™œ์šฉ

m.yes24.com

https://www.inflearn.com/course/%EC%8A%A4%ED%94%84%EB%A7%81-%ED%95%B5%EC%8B%AC-%EC%9B%90%EB%A6%AC-%EA%B3%A0%EA%B8%89%ED%8E%B8

 

์Šคํ”„๋ง ํ•ต์‹ฌ ์›๋ฆฌ - ๊ณ ๊ธ‰ํŽธ ๊ฐ•์˜ - ์ธํ”„๋Ÿฐ

์Šคํ”„๋ง์˜ ํ•ต์‹ฌ ์›๋ฆฌ์™€ ๊ณ ๊ธ‰ ๊ธฐ์ˆ ๋“ค์„ ๊นŠ์ด์žˆ๊ฒŒ ํ•™์Šตํ•˜๊ณ , ์Šคํ”„๋ง์„ ์ž์‹ ์žˆ๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค., ํ•ต์‹ฌ ๋””์ž์ธ ํŒจํ„ด, ์“ฐ๋ ˆ๋“œ ๋กœ์ปฌ, ์Šคํ”„๋ง AOP์Šคํ”„๋ง์˜ 3๊ฐ€์ง€ ํ•ต์‹ฌ ๊ณ ๊ธ‰ ๊ฐœ๋… ์ดํ•ดํ•˜๊ธฐ ๐Ÿ“ข ์ˆ˜๊ฐ•

www.inflearn.com

 

 
 
 
 
 
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€
Total
Today
Yesterday