Skip to content

Commit

Permalink
docs: 📝 update post
Browse files Browse the repository at this point in the history
  • Loading branch information
nyj001012 committed Apr 17, 2024
1 parent 3039919 commit add2159
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions _posts/springboot/2024-04-17-aop.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,31 @@ public class MyTimeTraceAOP {
}
```

# AOP 동작 방식
예시로 서비스의 한 함수에 `MyTimeTraceAOP`가 적용된다고 가정해보면 다음과 같은 순서로 동작한다.

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 647.3539299863644 554.1176259696573" width="647.3539299863644" height="554.1176259696573">
<!-- svg-source:excalidraw -->

<defs>
<style class="style-fonts">
@font-face {
font-family: "Virgil";
src: url("https://excalidraw.com/Virgil.woff2");
}
@font-face {
font-family: "Cascadia";
src: url("https://excalidraw.com/Cascadia.woff2");
}
</style>

</defs>
<rect x="0" y="0" width="647.3539299863644" height="554.1176259696573" fill="#ffffff"></rect><g stroke-linecap="round" transform="translate(286.2201142925828 99.41934782645203) rotate(0 146.03271029585207 184.62809446915998)"><path d="M0 0 C74.61 0, 149.22 0, 292.07 0 M292.07 0 C292.07 77.56, 292.07 155.11, 292.07 369.26 M292.07 369.26 C231.2 369.26, 170.33 369.26, 0 369.26 M0 369.26 C0 247.92, 0 126.59, 0 0" stroke="#1e1e1e" stroke-width="1.5" fill="none" stroke-dasharray="8 9"></path></g><g stroke-linecap="round" transform="translate(56.321656947741644 136.79931967102306) rotate(0 89.5 48.5)"><path d="M0 0 C38.11 0, 76.22 0, 179 0 M0 0 C50.26 0, 100.51 0, 179 0 M179 0 C179 23.87, 179 47.73, 179 97 M179 0 C179 19.93, 179 39.85, 179 97 M179 97 C125.24 97, 71.47 97, 0 97 M179 97 C115.99 97, 52.98 97, 0 97 M0 97 C0 72.46, 0 47.92, 0 0 M0 97 C0 76.25, 0 55.5, 0 0" stroke="#1e1e1e" stroke-width="1" fill="none"></path></g><g transform="translate(81.34411788524164 173.79931967102306) rotate(0 64.4775390625 11.5)"><text x="64.4775390625" y="0" font-family="Helvetica, Segoe UI Emoji" font-size="20px" fill="#1e1e1e" text-anchor="middle" style="white-space: pre;" direction="ltr" dominant-baseline="text-before-edge">helloController</text></g><g stroke-linecap="round" transform="translate(342.1506347449803 137.96239962072568) rotate(0 89.5 48.5)"><path d="M0 0 L179 0 L179 97 L0 97" stroke="none" stroke-width="0" fill="#ffc9c9"></path><path d="M0 0 C56.92 0, 113.83 0, 179 0 M0 0 C47.04 0, 94.07 0, 179 0 M179 0 C179 37.63, 179 75.26, 179 97 M179 0 C179 28.59, 179 57.17, 179 97 M179 97 C109.69 97, 40.38 97, 0 97 M179 97 C132.55 97, 86.1 97, 0 97 M0 97 C0 68.49, 0 39.98, 0 0 M0 97 C0 63.4, 0 29.8, 0 0" stroke="#1e1e1e" stroke-width="1" fill="none"></path></g><g transform="translate(377.1779784949803 163.46239962072568) rotate(0 54.47265625 23)"><text x="54.47265625" y="0" font-family="Helvetica, Segoe UI Emoji" font-size="20px" fill="#1e1e1e" text-anchor="middle" style="white-space: pre;" direction="ltr" dominant-baseline="text-before-edge">프록시</text><text x="54.47265625" y="23" font-family="Helvetica, Segoe UI Emoji" font-size="20px" fill="#1e1e1e" text-anchor="middle" style="white-space: pre;" direction="ltr" dominant-baseline="text-before-edge">helloService</text></g><g stroke-linecap="round" transform="translate(343.40736842423877 342.1767621836451) rotate(0 89.5 48.5)"><path d="M0 0 L179 0 L179 97 L0 97" stroke="none" stroke-width="0" fill="#b2f2bb"></path><path d="M0 0 C35.98 0, 71.97 0, 179 0 M0 0 C60.08 0, 120.16 0, 179 0 M179 0 C179 30.01, 179 60.02, 179 97 M179 0 C179 26.84, 179 53.68, 179 97 M179 97 C113.28 97, 47.55 97, 0 97 M179 97 C133.72 97, 88.43 97, 0 97 M0 97 C0 68.59, 0 40.18, 0 0 M0 97 C0 74.75, 0 52.51, 0 0" stroke="#1e1e1e" stroke-width="1" fill="none"></path></g><g transform="translate(378.43471217423877 367.6767621836451) rotate(0 54.47265625 23)"><text x="54.47265625" y="0" font-family="Helvetica, Segoe UI Emoji" font-size="20px" fill="#1e1e1e" text-anchor="middle" style="white-space: pre;" direction="ltr" dominant-baseline="text-before-edge">스프링</text><text x="54.47265625" y="23" font-family="Helvetica, Segoe UI Emoji" font-size="20px" fill="#1e1e1e" text-anchor="middle" style="white-space: pre;" direction="ltr" dominant-baseline="text-before-edge">helloService</text></g><g stroke-linecap="round"><g transform="translate(235.7130260735364 185.8612673784328) rotate(0 52.95312910007124 0)"><path d="M0 0 C42.05 0, 84.1 0, 105.91 0 M0 0 C29.1 0, 58.2 0, 105.91 0" stroke="#1e1e1e" stroke-width="1" fill="none"></path></g><g transform="translate(235.7130260735364 185.8612673784328) rotate(0 52.95312910007124 0)"><path d="M77.72 10.26 C88.91 6.19, 100.1 2.11, 105.91 0 M77.72 10.26 C85.46 7.44, 93.21 4.62, 105.91 0" stroke="#1e1e1e" stroke-width="1" fill="none"></path></g><g transform="translate(235.7130260735364 185.8612673784328) rotate(0 52.95312910007124 0)"><path d="M77.72 -10.26 C88.91 -6.19, 100.1 -2.11, 105.91 0 M77.72 -10.26 C85.46 -7.44, 93.21 -4.62, 105.91 0" stroke="#1e1e1e" stroke-width="1" fill="none"></path></g></g><mask></mask><g mask="url(#mask-pThA-CoDpOIkdfyVvribP)" stroke-linecap="round"><g transform="translate(432.6904945059661 234.7544245573476) rotate(0 0 53.211168813148774)"><path d="M0 0 C0 41.19, 0 82.38, 0 106.42 M0 0 C0 37.01, 0 74.02, 0 106.42" stroke="#1e1e1e" stroke-width="1" fill="none"></path></g><g transform="translate(432.6904945059661 234.7544245573476) rotate(0 0 53.211168813148774)"><path d="M-10.26 78.23 C-6.29 89.14, -2.32 100.05, 0 106.42 M-10.26 78.23 C-6.69 88.03, -3.12 97.84, 0 106.42" stroke="#1e1e1e" stroke-width="1" fill="none"></path></g><g transform="translate(432.6904945059661 234.7544245573476) rotate(0 0 53.211168813148774)"><path d="M10.26 78.23 C6.29 89.14, 2.32 100.05, 0 106.42 M10.26 78.23 C6.69 88.03, 3.12 97.84, 0 106.42" stroke="#1e1e1e" stroke-width="1" fill="none"></path></g></g><mask id="mask-pThA-CoDpOIkdfyVvribP"><rect x="0" y="0" fill="#fff" width="532.6904945059662" height="441.1767621836451"></rect><rect x="348.7549476309661" y="276.4655933704964" fill="#000" width="167.87109375" height="23" opacity="1"></rect></mask><g transform="translate(348.7549476309661 276.4655933704964) rotate(0 83.935546875 11.5)"><text x="83.935546875" y="0" font-family="Helvetica, Segoe UI Emoji" font-size="20px" fill="#1e1e1e" text-anchor="middle" style="white-space: pre;" direction="ltr" dominant-baseline="text-before-edge">joinPoint.proceed()</text></g><g stroke-linecap="round" transform="translate(10 10) rotate(0 313.6769649931822 246.3056031164949)"><path d="M0 0 C213.87 0, 427.74 0, 627.35 0 M0 0 C219.21 0, 438.43 0, 627.35 0 M627.35 0 C627.35 130.08, 627.35 260.16, 627.35 492.61 M627.35 0 C627.35 195.16, 627.35 390.32, 627.35 492.61 M627.35 492.61 C483.82 492.61, 340.29 492.61, 0 492.61 M627.35 492.61 C405.42 492.61, 183.48 492.61, 0 492.61 M0 492.61 C0 354, 0 215.38, 0 0 M0 492.61 C0 310.27, 0 127.94, 0 0" stroke="#1e1e1e" stroke-width="1" fill="none"></path></g><g transform="translate(234.16713072547884 23.127903419888412) rotate(0 88.65959930419922 16.099999999999994)"><text x="0" y="0" font-family="Helvetica, Segoe UI Emoji" font-size="28px" fill="#1e1e1e" text-anchor="start" style="white-space: pre;" direction="ltr" dominant-baseline="text-before-edge">스프링 컨테이너</text></g><g transform="translate(236.08933248136157 514.6811345447951) rotate(0 199.38407205744295 14.718245712431099)"><text x="0" y="0" font-family="Helvetica, Segoe UI Emoji" font-size="12.798474532548772px" fill="#1e1e1e" text-anchor="start" style="white-space: pre;" direction="ltr" dominant-baseline="text-before-edge">출처: 김영한, 스프링 입문 - 코드로 배우는 스프링 부트, 웹 MVC, DB 접근 기술</text><text x="0" y="14.718245712431086" font-family="Helvetica, Segoe UI Emoji" font-size="12.798474532548772px" fill="#1e1e1e" text-anchor="start" style="white-space: pre;" direction="ltr" dominant-baseline="text-before-edge"></text></g></svg>

1. `helloController`에서 `helloService`를 호출한다.
2. 스프링 컨테이너에 등록된 실제 스프링 `helloService` 대신, **프록시 `helloService`를 호출**한다.
3. 프록시 `helloService` 내에서 `joinPoint.proceed()`를 실행하면 그때 스프링 `helloService`를 실행한다.

# 여담
## `TimeTraceAOP` 였던 것
`MyTimeTraceAOP` 클래스를 만들 때 처음에는 `TimeTraceAOP`로 했다가 Bean을 만들 때 이미 같은 이름이 있다고 빌드를 실패했다...
Expand Down

0 comments on commit add2159

Please sign in to comment.