on
예제로 배우는 스프링 프레임워크 입문 - 스프링 AOP
예제로 배우는 스프링 프레임워크 입문 - 스프링 AOP
AOP 소개
Aspect Oriented Programming
흩어진 코드를 한 곳으로 모아
Spring -> IOC, AOP, PSA (Spring Triangle)
@Transactional -> AOP 기반 어노테이션
흩어진 AAAA 와 BBBB
class A { method a () { AAAA -> AAA 오늘은 7월 4일 미국 독립 기념일이래요. BBBB -> BB } method b () { AAAA -> AAA 저는 아침에 운동을 다녀와서 밥먹고 빨래를 했습니다. BBBB -> BB } } class B { method c() { AAAA -> AAA 점심은 이거 찍느라 못먹었는데 저녁엔 제육볶음을 먹고 싶네요. BBBB -> BB } }
모아 놓은 AAAA 와 BBBB
class A { method a () { 오늘은 7월 4일 미국 독립 기념일이래요. } method b () { 저는 아침에 운동을 다녀와서 밥먹고 빨래를 했습니다. } } class B { method c() { 점심은 이거 찍느라 못먹었는데 저녁엔 제육볶음을 먹고 싶네요. } } class AAAABBBB { method aaaabbb(JoinPoint point) { AAAA point.execute() BBBB } }
@GetMapping("/owners/new") public String initCreationForm(Map model) { /* StopWatch stopWatch = new StopWatch(); stopWatch.start(); */ Owner owner = new Owner(); model.put("owner", owner); /* stopWatch.stop(); System.out.println(stopWatch.prettyPrint()); */ return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; }
다양한 AOP 구현 방법
컴파일 A.java ----(AOP)---> A.class ( AspectJ
바이트코드 조작 A.java -> A.class ---(AOP)---> 메모리 (AspectJ)
프록시 패턴 (스프링 AOP)
https://github.com/devjun63/spring-petclinic/commit/5988b867bd4376eb5ac965ba9d5d1adea3880123
from http://devjun.tistory.com/237 by ccl(A) rewrite - 2021-12-03 00:27:16