Category: Spring AOP

0

Spring AOP Pointcut 표현식 - this, target

목차 Spring AOP Pointcut 표현식 - this, target Spring AOP Pointcut 표현식 - 매게변수 전달 Spring AOP Pointcut 표현식 - bean Spring AOP Pointcut 표현식 - @annotation, @args Spring AOP Pointcut 표현식 - @target, @within Spring AOP Pointcut 표현식 - args Spring AOP Pointcut 표현식 - within Spring AOP - Pointcut 표현식 execution Spring 핵심원리 고급편 - Pointcut Spring 핵심원리 고급편 - this, target

0

Spring AOP Pointcut 표현식 - 매게변수 전달

목차 Spring AOP Pointcut 표현식 - this, target Spring AOP Pointcut 표현식 - 매게변수 전달 Spring AOP Pointcut 표현식 - bean Spring AOP Pointcut 표현식 - @annotation, @args Spring AOP Pointcut 표현식 - @target, @within Spring AOP Pointcut 표현식 - args Spring AOP Pointcut 표현식 - within Spring AOP - Pointcut 표현식 execution Spring 핵심원리 고급편 - Pointcut Spring 핵심원리 고급편 - 매게변수 전달

0

Spring AOP Pointcut 표현식 - bean

목차 Spring AOP Pointcut 표현식 - this, target Spring AOP Pointcut 표현식 - 매게변수 전달 Spring AOP Pointcut 표현식 - bean Spring AOP Pointcut 표현식 - @annotation, @args Spring AOP Pointcut 표현식 - @target, @within Spring AOP Pointcut 표현식 - args Spring AOP Pointcut 표현식 - within Spring AOP - Pointcut 표현식 execution Spring 핵심원리 고급편 - Pointcut @Slf4j@Import(BeanTest.BeanAspect.class)@SpringBootTestpublic class BeanTest { @Autowired OrderService orderService; @Test void success(){ orderService.orderItem("itemA"); } @Aspect static class BeanAspect{ @Around("bean(orderService) || bean(*Repository)") public Object doLog(ProceedingJoinPoint joinPoint) throws Throwable { log.info("[bean] {}", joinPoint.getSignature()); return joinPoint.proceed(); } }} 2021-12-21 00:13:43.463 INFO 35836 --- [ Test worker] com.example.aop.pointcut.BeanTest : [bean] void com.example.aop.order.OrderService.orderItem(String)2021-12-21 00:13:43.474 INFO 35836 --- [ Test worker] com.example.aop.order.OrderService : [orderService] 실행2021-12-21 00:13:43.475 INFO 35836 --- [ Test worker] com.example.aop.pointcut.BeanTest : [bean] String com.example.aop.order.OrderRepository.save(String)2021-12-21 00:13:43.480 INFO 35836 --- [ Test worker] com.example.aop.order.OrderRepository : [orderRepository] 실행

0

Spring AOP Pointcut 표현식 - @annotation, @args

목차 Spring AOP Pointcut 표현식 - this, target Spring AOP Pointcut 표현식 - 매게변수 전달 Spring AOP Pointcut 표현식 - bean Spring AOP Pointcut 표현식 - @annotation, @args Spring AOP Pointcut 표현식 - @target, @within Spring AOP Pointcut 표현식 - args Spring AOP Pointcut 표현식 - within Spring AOP - Pointcut 표현식 execution Spring 핵심원리 고급편 - Pointcut @annotation 메서드가 주어진 어노테이션을 가지고 있는 조인 포인트를 매칭 Spring 에서는 특정 어노테이션이 적용된 메소드에 Advice 를 적용하기 위해 Pointcut 표현식 에서 @annotation 을 제공합니다. Custom Annotation 생성@Target(ElementType.METHOD)@Retention(RetentionPolicy.RUNTIME)public @interface MethodAop { String value();} Advisor 생성어노테이션을 이용해 Advice 적용하기 위해 @annotation 에 어노테이션 패키지 경로를 지정합니다. @Slf4j@Aspectstatic class AtAnnotationAspect{ @Around("@annotation(com.example.aop.member.annotation.MethodAop)") public Object doAtAnnotation(ProceedingJoinPoint joinPoint) throws Throwable { log.info("[@annotation] {}", joinPoint.getSignature()); return joinPoint.proceed(); }}

0

Spring AOP Pointcut 표현식 - @target, @within

목차 Spring AOP Pointcut 표현식 - this, target Spring AOP Pointcut 표현식 - 매게변수 전달 Spring AOP Pointcut 표현식 - bean Spring AOP Pointcut 표현식 - @annotation, @args Spring AOP Pointcut 표현식 - @target, @within Spring AOP Pointcut 표현식 - args Spring AOP Pointcut 표현식 - within Spring AOP - Pointcut 표현식 execution Spring 핵심원리 고급편 - Pointcut @target 과 @within@target 은 부모 클래스의 메서드까지 Advice 를 다 적용하고, @within 은 정의된 클래스내 메서드에만 Advice 를 적용합니다. Custon Annotation 생성@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)public @interface ClassAop {} Advisor 생성@Slf4j@Aspectstatic class AtTargetAtWithinAspect { //@target: 인스턴스 기준으로 모든 메서드의 조인 포인트를 선정, 부모 타입의 메서드도 적용 @Around("execution(* com.example.aop..*(..)) && @target(com.example.aop.member.annotation.ClassAop)") public Object atTarget(ProceedingJoinPoint joinPoint) throws Throwable { log.info("[@target] {}", joinPoint.getSignature()); return joinPoint.proceed(); } //@within: 선택된 클래스 내부에 있는 메서드만 조인 포인트로 선정, 부모 타입의 메서드는 적용되지 않음 @Around("execution(* com.example.aop..*(..)) && @within(com.example.aop.member.annotation.ClassAop)") public Object atWithin(ProceedingJoinPoint joinPoint) throws Throwable { log.info("[@within] {}", joinPoint.getSignature()); return joinPoint.proceed(); }} AOP 적용 확인

0

Spring AOP Pointcut 표현식 - args

목차 Spring AOP Pointcut 표현식 - this, target Spring AOP Pointcut 표현식 - 매게변수 전달 Spring AOP Pointcut 표현식 - bean Spring AOP Pointcut 표현식 - @annotation, @args Spring AOP Pointcut 표현식 - @target, @within Spring AOP Pointcut 표현식 - args Spring AOP Pointcut 표현식 - within Spring AOP - Pointcut 표현식 execution Spring 핵심원리 고급편 - Pointcut Spring 핵심원리 고급편 - args execution 은 파라미터 타입이 정확하게 일치돼야 한다. execution 은 클래스에 선언된 정보를 기반으로 판단한다. args 는 부모타입을 허용한다. args 는 실제로 넘어온 파라미터 객체 인스턴스를 보고 판단한다. private AspectJExpressionPointcut pointcut(String expression) { AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut(); pointcut.setExpression(expression); return pointcut;}@Testvoid args() { //hello(String)과 매칭 assertThat(pointcut("args(String)") .matches(helloMethod, MemberServiceImpl.class)).isTrue(); assertThat(pointcut("args(Object)") .matches(helloMethod, MemberServiceImpl.class)).isTrue(); assertThat(pointcut("args()") .matches(helloMethod, MemberServiceImpl.class)).isFalse(); assertThat(pointcut("args(..)") .matches(helloMethod, MemberServiceImpl.class)).isTrue(); assertThat(pointcut("args(*)") .matches(helloMethod, MemberServiceImpl.class)).isTrue(); assertThat(pointcut("args(String,..)") .matches(helloMethod, MemberServiceImpl.class)).isTrue();} /** * execution(* *(java.io.Serializable)): 메서드의 시그니처로 판단 (정적) * args(java.io.Serializable): 런타임에 전달된 인수로 판단 (동적) */@Testvoid argsVsExecution() { // Args // args 는 상위 타입도 허용한다. assertThat(pointcut("args(String)") .matches(helloMethod, MemberServiceImpl.class)).isTrue(); assertThat(pointcut("args(java.io.Serializable)") .matches(helloMethod, MemberServiceImpl.class)).isTrue(); assertThat(pointcut("args(Object)") .matches(helloMethod, MemberServiceImpl.class)).isTrue(); // Execution // execution 은 정확하게 매칭돼야 한다. assertThat(pointcut("execution(* *(String))") .matches(helloMethod, MemberServiceImpl.class)).isTrue(); assertThat(pointcut("execution(* *(java.io.Serializable))") //매칭 실패 .matches(helloMethod, MemberServiceImpl.class)).isFalse(); assertThat(pointcut("execution(* *(Object))") //매칭 실패 .matches(helloMethod, MemberServiceImpl.class)).isFalse();}

0

Spring AOP Pointcut 표현식 - within

목차 Spring AOP Pointcut 표현식 - this, target Spring AOP Pointcut 표현식 - 매게변수 전달 Spring AOP Pointcut 표현식 - bean Spring AOP Pointcut 표현식 - @annotation, @args Spring AOP Pointcut 표현식 - @target, @within Spring AOP Pointcut 표현식 - args Spring AOP Pointcut 표현식 - within Spring AOP - Pointcut 표현식 execution Spring 핵심원리 고급편 - Pointcut within within 은 특정 타입 에 대해 Advice 를 적용합니다. 특정 타입이 within 을 만족 하면 해당 타입내 모든 메소드는 Advice 가 적용됩니다. // com.example.aop.member.MemberServiceImpl 타입을 대상으로 Advice 를 적용합니다.within(com.example.aop.member.MemberServiceImpl)// com.example.aop.member 패키지내 타입 이름에 Service 가 들어가면 Advice 를 적욯합니다.within(com.example.aop.member.*Service*)// com.example.aop 패키지와 하위 패키지내 모든 타입에 Advice 를 적용합니다.within(com.example.aop..*) execution 과 within 의 차이within 은 표현식은 execution 과 다르게 부모 타입을 지정했을 경우 자식 타입에는 Advice 가 적용되지 않습니다. 즉, 상속이나 구현을 통해 생성된 객체에는 Advice 가 적용되지 않고 정확하게 지정된 타입에만 적용되는 점에서 execution 과 차이가 있습니다. @Test@DisplayName("타겟의 타입에만 직접 적용, 인터페이스를 선정하면 안된다.")void withinSuperTypeFalse() { pointcut.setExpression("within(com.example.aop.member.MemberService)"); assertThat(pointcut.matches(helloMethod, MemberServiceImpl.class)).isFalse();}@Test@DisplayName("execution은 타입 기반, 인터페이스 선정 가능")void executionSuperTypeTrue() { pointcut.setExpression("execution(* com.example.aop.member.MemberService.*(..))"); assertThat(pointcut.matches(helloMethod, MemberServiceImpl.class)).isTrue();}

0

Spring AOP - Pointcut 표현식 execution

목차 Spring AOP Pointcut 표현식 - this, target Spring AOP Pointcut 표현식 - 매게변수 전달 Spring AOP Pointcut 표현식 - bean Spring AOP Pointcut 표현식 - @annotation, @args Spring AOP Pointcut 표현식 - @target, @within Spring AOP Pointcut 표현식 - args Spring AOP Pointcut 표현식 - within Spring AOP - Pointcut 표현식 execution Spring 핵심원리 고급편 - Pointcut execution execution( [접근제어자] 리턴타입 [선언타입] 메서드이름 (파라미터) [예외] ) execution 는 Pointcut 표현식에서 가장 많이 사용되는 명시자 입니다. execution 는 메소드의 접근 제어자, 리턴 타입, 메소드가 선언된 패키지, 클래스 정보, 메소드 파라미터, 예외처리 정보를 이용해 다양한 조건으로 Pointcut 을 적용할 수 있도록 제공합니다. execution(public String com.example.aop.member.MemberServiceImpl.hello(String)) 접근 제어자 : public 인 메소드 리턴 타입 : String 선언 타입 : com.example.aop.member.MemberServiceImpl 메서드 이름 : hello 파라미터 : String 예외 : 생략 @Testvoid exactMatch(){ // public java.lang.String com.example.aop.member.MemberServiceImpl.hello(java.lang.String) pointcut.setExpression("execution(public String com.example.aop.member.MemberServiceImpl.hello(String))"); assertThat(pointcut.matches(helloMethod, MemberServiceImpl.class)).isTrue();}

0

Spring 핵심원리 고급편 - Pointcut

목차 Spring AOP Pointcut 표현식 - this, target Spring AOP Pointcut 표현식 - 매게변수 전달 Spring AOP Pointcut 표현식 - bean Spring AOP Pointcut 표현식 - @annotation, @args Spring AOP Pointcut 표현식 - @target, @within Spring AOP Pointcut 표현식 - args Spring AOP Pointcut 표현식 - within Spring AOP - Pointcut 표현식 execution Spring 핵심원리 고급편 - Pointcut @Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)public @interface ClassAop {} @Target(ElementType.METHOD)@Retention(RetentionPolicy.RUNTIME)public @interface MethodAop { String value();} public interface MemberService { String hello(String param);} @ClassAop@Componentpublic class MemberServiceImpl implements MemberService { @Override @MethodAop("test") public String hello(String param) { return null; } public String internal(String param){ return "ok"; }} AspectJExpressionPointcut 이 포인트 컷 표현식을 처리해주는 클래스 @Slf4jpublic class ExecutionTest { AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut(); Method helloMethod; @BeforeEach public void init() throws NoSuchMethodException { helloMethod = MemberServiceImpl.class.getMethod("hello", String.class); } @Test void printMethod(){ log.info("helloMethod = {}", helloMethod); }}

0

Spring AOP - Advice 종류

목차 Spring AOP - Advice 종류 Spring AOP - 트랜잭션 순서 Spring AOP - Pointcut 참조 Spring AOP - 어드바이스 추가 Spring AOP - Pointcut 분리 Spring AOP - @Aspect Spring AOP - Aspect Spring AOP - 용어 정리 Spring AOP - 적용 방식 Spring 핵심원리 고급편 - 어드바이스 종류 종류 설명 @Around 메서드 호출 전 후에 실행, 가장 강력한 어드바이스, 조인 포인트 실행 여부 선택, 반환 값 변환, 예외 변환 등이 가능 @Before 조인 포인트 실행 이전에 실행 @AfterReturning 조인 포인트가 정상 완료 후 실행 @AftThrowing 메서드가 예외를 던지는 경우 실행 @After 조인 포인트가 정상 또는 예외에 관계 없이 실행 @Slf4j@Aspectpublic class AspectV6Advice { // com.example.aop.order 하위 패키지면서 클래스 이름 패턴이 *Service 인 것 @Around("com.example.aop.order.aop.Pointcuts.orderAndService()") public Object doTransaction(ProceedingJoinPoint joinPoint) throws Throwable{ try{ // @Before log.info("[트랜잭션 시작] {}", joinPoint.getSignature()); Object result = joinPoint.proceed(); // @AfterReturning log.info("[트랜잭션 커밋] {}", joinPoint.getSignature()); return result; }catch (Exception ex){ // @AfterThrowing log.info("[트랜잭션 롤백] {}", joinPoint.getSignature()); throw ex; }finally { // @After log.info("[리소스 릴리즈] {}", joinPoint.getSignature()); } }} @Slf4j@Aspectpublic class AspectV6Advice { // com.example.aop.order 하위 패키지면서 클래스 이름 패턴이 *Service 인 것 @Around("com.example.aop.order.aop.Pointcuts.orderAndService()") public Object doTransaction(ProceedingJoinPoint joinPoint) throws Throwable{ try{ // @Before log.info("[트랜잭션 시작] {}", joinPoint.getSignature()); Object result = joinPoint.proceed(); // @AfterReturning log.info("[트랜잭션 커밋] {}", joinPoint.getSignature()); return result; }catch (Exception ex){ // @AfterThrowing log.info("[트랜잭션 롤백] {}", joinPoint.getSignature()); throw ex; }finally { // @After log.info("[리소스 릴리즈] {}", joinPoint.getSignature()); } } // @Before 은 그냥 실행해준다. @Before("com.example.aop.order.aop.Pointcuts.orderAndService()") public void doBefore(JoinPoint joinPoint){ log.info("[before] {}", joinPoint.getSignature()); } // return 값을 조작을 할 수는 있지만 바꿀 수 는 없다. @AfterReturning(value = "com.example.aop.order.aop.Pointcuts.orderAndService()", returning = "result") public void doReturn(JoinPoint joinPoint, Object result){ log.info("[return] {} return = {}", joinPoint.getSignature(), result); } // 자동으로 throw ex 를 해준다. @AfterThrowing(value = "com.example.aop.order.aop.Pointcuts.orderAndService()", throwing = "ex") public void doThrowing(JoinPoint joinPoint, Exception ex){ log.info("[ex] {} message = {}", ex); } @After(value = "com.example.aop.order.aop.Pointcuts.orderAndService()") public void doAfter(JoinPoint joinPoint){ log.info("[after] {}", joinPoint.getSignature()); }} 모든 어드바이스는 JoinPoint 를 첫번째 파라미터에 사용할 수 있다. 단 @Around 는 ProceedingJoinPoint 를 사용해야 한다.ProceedingJoinPoint는 JoinPoint 의 하위 타입니다. JoinPoint 인터페이스의 주요 기능 Method 설명 getArgs 메서드 인수를 반환한다. getThis 프록시 객체를 반환한다. getTarget 대상 객체를 반환한다. getSignature 조언되는 메서드에 대한 설명을 반환한다. toString 조언되는 방법에 대한 유용한 설명을 인쇄한다.

0

Spring AOP - 트랜잭션 순서

목차 Spring AOP - Advice 종류 Spring AOP - 트랜잭션 순서 Spring AOP - Pointcut 참조 Spring AOP - 어드바이스 추가 Spring AOP - Pointcut 분리 Spring AOP - @Aspect Spring AOP - Aspect Spring AOP - 용어 정리 Spring AOP - 적용 방식 Spring 핵심원리 고급편 - 트랜잭션 순서@Slf4jpublic class AspectV5Order { @Aspect @Order(2) public static class LogAspect{ @Around("com.example.aop.order.aop.Pointcuts.allOrder()") public Object doLog(ProceedingJoinPoint joinPoint) throws Throwable{ log.info("[log] {}", joinPoint.getSignature()); // join point 시그니처 return joinPoint.proceed(); } } @Aspect @Order(1) public static class TxAspect{ // com.example.aop.order 하위 패키지면서 클래스 이름 패턴이 *Service 인 것 @Around("com.example.aop.order.aop.Pointcuts.orderAndService()") public Object doTransaction(ProceedingJoinPoint joinPoint) throws Throwable{ try{ log.info("[트랜잭션 시작] {}", joinPoint.getSignature()); Object result = joinPoint.proceed(); log.info("[트랜잭션 커밋] {}", joinPoint.getSignature()); return result; }catch (Exception ex){ log.info("[트랜잭션 롤백] {}", joinPoint.getSignature()); throw ex; }finally { log.info("[리소스 릴리즈] {}", joinPoint.getSignature()); } } }}

0

Spring AOP - Pointcut 참조

목차 Spring AOP - Advice 종류 Spring AOP - 트랜잭션 순서 Spring AOP - Pointcut 참조 Spring AOP - 어드바이스 추가 Spring AOP - Pointcut 분리 Spring AOP - @Aspect Spring AOP - Aspect Spring AOP - 용어 정리 Spring AOP - 적용 방식 Pointcutpublic class Pointcuts { @Pointcut("execution(* com.example.aop.order..*(..))") public void allOrder(){} // 클래스 이름 패턴이 *Service @Pointcut("execution(* *..*Service.*(..))") public void allService(){} // allOrder && allService @Pointcut("allOrder() && allService()") public void orderAndService(){}} 외부 Pointcut 참조@Slf4j@Aspectpublic class AspectV4PointCut { @Around("com.example.aop.order.aop.Pointcuts.allOrder()") public Object doLog(ProceedingJoinPoint joinPoint) throws Throwable{ log.info("[log] {}", joinPoint.getSignature()); // join point 시그니처 return joinPoint.proceed(); } // com.example.aop.order 하위 패키지면서 클래스 이름 패턴이 *Service 인 것 @Around("com.example.aop.order.aop.Pointcuts.orderAndService()") public Object doTransaction(ProceedingJoinPoint joinPoint) throws Throwable{ try{ log.info("[트랜잭션 시작] {}", joinPoint.getSignature()); Object result = joinPoint.proceed(); log.info("[트랜잭션 커밋] {}", joinPoint.getSignature()); return result; }catch (Exception ex){ log.info("[트랜잭션 롤백] {}", joinPoint.getSignature()); throw ex; }finally { log.info("[리소스 릴리즈] {}", joinPoint.getSignature()); } }} @Slf4j@SpringBootTest@Import(AspectV4PointCut.class)public class AopTest { @Autowired OrderService orderService; @Autowired OrderRepository orderRepository; @Test public void aopTest(){ log.info("isAopProxy, orderService = {}", AopUtils.isAopProxy(orderService)); log.info("isAopProxy, orderRepository = {}", AopUtils.isAopProxy(orderRepository)); } @Test public void success(){ orderService.orderItem("itemA"); } @Test public void exception(){ assertThatThrownBy(() -> orderService.orderItem("ex")) .isInstanceOf(IllegalStateException.class); }}

0

Spring AOP - 어드바이스 추가

목차 Spring AOP - Advice 종류 Spring AOP - 트랜잭션 순서 Spring AOP - Pointcut 참조 Spring AOP - 어드바이스 추가 Spring AOP - Pointcut 분리 Spring AOP - @Aspect Spring AOP - Aspect Spring AOP - 용어 정리 Spring AOP - 적용 방식 Advice 추가 기존에 로그를 찍은 기능에서 트랜잭션 기능 추가 allOrder com.example.aop.order 하위 패키지를 대상으로 포인트 컷 적용 allService 타입 이름 패턴이 *Service 를 대상으로 포인트 컷 적용 타입 이름 패턴 : 클래스, 인터페이스 모두 적용 @Around(“allOrder() && allService()”) 포인트 컷은 조합이 가능하다 && : AND || : OR ! : NOT @Slf4j@Aspectpublic class AspectV3 { @Pointcut("execution(* com.example.aop.order..*(..))") private void allOrder(){} // 클래스 이름 패턴이 *Service @Pointcut("execution(* *..*Service.*(..))") private void allService(){} @Around("allOrder()") public Object doLog(ProceedingJoinPoint joinPoint) throws Throwable{ log.info("[log] {}", joinPoint.getSignature()); // join point 시그니처 return joinPoint.proceed(); } // com.example.aop.order 하위 패키지면서 클래스 이름 패턴이 *Service 인 것 @Around("allOrder() && allService()") public Object doTransaction(ProceedingJoinPoint joinPoint) throws Throwable{ try{ log.info("[트랜잭션 시작] {}", joinPoint.getSignature()); Object result = joinPoint.proceed(); log.info("[트랜잭션 커밋] {}", joinPoint.getSignature()); return result; }catch (Exception ex){ log.info("[트랜잭션 롤백] {}", joinPoint.getSignature()); throw ex; }finally { log.info("[리소스 릴리즈] {}", joinPoint.getSignature()); } }}

0

Spring AOP - Pointcut 분리

목차 Spring AOP - Advice 종류 Spring AOP - 트랜잭션 순서 Spring AOP - Pointcut 참조 Spring AOP - 어드바이스 추가 Spring AOP - Pointcut 분리 Spring AOP - @Aspect Spring AOP - Aspect Spring AOP - 용어 정리 Spring AOP - 적용 방식 Spring 핵심원리 고급편 - Pointcut 분리 하나의 Pointcut 표현식을 여러 어드바이스에서 함께 사용하는 것이 가능하다. @Pointcut 에 포인트 컷 표현식을 사용한다. 메서드 이름과 파라미터를 합처서 Signature(시그니처) 라고 한다. 메서드의 반환 타입은 void 여야 한다. 코드 내용은 비워둔다. @Slf4j@Aspectpublic class AspectV2 { @Pointcut("execution(* com.example.aop.order..*(..))") private void allOrder(){ } @Around("allOrder()") public Object doLog(ProceedingJoinPoint joinPoint) throws Throwable{ log.info("[log] {}", joinPoint.getSignature()); // join point 시그니처 return joinPoint.proceed(); }} @Slf4j@SpringBootTest//@Import(AspectV1.class) // Bean 등록@Import(AspectV2.class)public class AopTest { @Autowired OrderService orderService; @Autowired OrderRepository orderRepository; @Test public void aopTest(){ log.info("isAopProxy, orderService = {}", AopUtils.isAopProxy(orderService)); log.info("isAopProxy, orderRepository = {}", AopUtils.isAopProxy(orderRepository)); } @Test public void success(){ orderService.orderItem("itemA"); } @Test public void exception(){ assertThatThrownBy(() -> orderService.orderItem("ex")) .isInstanceOf(IllegalStateException.class); }}

0

Spring AOP - @Aspect

목차 Spring AOP - Advice 종류 Spring AOP - 트랜잭션 순서 Spring AOP - Pointcut 참조 Spring AOP - 어드바이스 추가 Spring AOP - Pointcut 분리 Spring AOP - @Aspect Spring AOP - Aspect Spring AOP - 용어 정리 Spring AOP - 적용 방식 @Aspect 작동방식 실행 스프링 어플리케이션 로딩 시점에 자동 프록시 생성기 를 호출한다. 모든 @Aspect Bean 조회 스프링 컨테이너에서 @Aspect Advisor 생성 @Aspect 어드바이저 빌더 를 통해 어드바이저를 생성한다. Aspect 기반 어드바이저 저장 생성한 어드바이저를 @Aspect 어드바이저 빌더 내부에 저장한다. 자동 프록시 생성기 역할@Aspect 가 적용된 Bean 들을 조회합니다. 해당 Bean 내 정의된 Advice 와 Pointcut 표현식을 이용해 Advisor 를 생성 후 저장합니다. Bean 객체 생성시 Bean 후처리기에서 Advisor 객체를 조회해 Pointcut 표현식에 해당되는 Bean 이 있을 경우 자동 프록시 생성기에서 Advice(부가기능) 가 적용된 프록시 객체를 생성합니다. @Aspect 사용하기