일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- JPQL
- AOP
- transaction
- 스프링 핵심 기능
- pointcut
- spring
- 자바
- java
- 백준
- JDBC
- 김영한
- Thymeleaf
- Android
- 그리디
- kotlin
- Greedy
- 알고리즘
- 스프링
- jpa
- db
- Spring Boot
- Exception
- 인프런
- QueryDSL
- Servlet
- SpringBoot
- http
- Proxy
- 스프링 핵심 원리
- springdatajpa
- Today
- Total
목록인프런/[인프런] 스프링 핵심 원리 - 고급 (105)
개발자되기 프로젝트
args : 인자가 주어진 타입의 인스턴스인 조인 포인트로 매칭 기본 문법은 execution 의 args 부분과 같다. 1. execution과 args의 차이점 execution 은 파라미터 타입이 정확하게 매칭되어야 한다. execution 은 클래스에 선언된 정보를 기반으로 판단한다. args 는 부모 타입을 허용한다. args 는 실제 넘어온 파라미터 객체 인스턴스를 보고 판단한다. 2. Argstest @Slf4j public class ArgsTest { Method helloMethod; @BeforeEach public void init() throws NoSuchMethodException { helloMethod = MemberServiceImpl.class.getMethod("hel..
within 지시자는 특정 타입 내의 조인 포인트에 대한 매칭을 제한한다. 쉽게 이야기해서 해당 타입이 매칭되면 그 안의 메서드(조인 포인트)들이 자동으로 매칭된다. 문법은 단순한데 execution 에서 타입 부분만 사용한다고 보면 된다. 1. Test @Slf4j public class WithinTest { AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut(); Method helloMethod; @BeforeEach public void init() throws NoSuchMethodException { helloMethod = MemberServiceImpl.class.getMethod("hello", String.class)..
1. 타입 매칭 - 부모 타입 허용 @Test void typeExactMatch(){ pointcut.setExpression("execution(* hello.aop.member.MemberServiceImpl.*(..))"); assertThat(pointcut.matches(helloMethod, MemberServiceImpl.class)).isTrue(); } @Test void typeMatchSuperType(){ pointcut.setExpression("execution(* hello.aop.member.MemberService.*(..))"); assertThat(pointcut.matches(helloMethod, MemberServiceImpl.class)).isTrue(); } ..
1. execution 문법 execution(modifiers-pattern? ret-type-pattern declaring-type-pattern?namepattern(param-pattern) throws-pattern?) execution(접근제어자? 반환타입 선언타입?메서드이름(파라미터) 예외?) 메소드 실행 조인 포인트를 매칭한다. ?는 생략할 수 있다. * 같은 패턴을 지정할 수 있다. 2. 가장 정확한 포인트컷 먼저 MemberServiceImpl.hello(String) 메서드와 가장 정확하게 모든 내용이 매칭되는 표현식이다. @Slf4j public class ExecutionTest { AspectJExpressionPointcut pointcut = new AspectJExpres..
1. Annotation @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface ClassAop { } @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) //Runtime때까지 annotation유지 public @interface MethodAop { String value(); } @Target: Indicates the contexts in which an annotation type is applicable. @Retention: Indicates how long annotations with the annotated type are to be r..
애스펙트J는 포인트컷을 편리하게 표현하기 위한 특별한 표현식을 제공한다. 예) @Pointcut("execution(* hello.aop.order..*(..))") 포인트컷 표현식은 AspectJ pointcut expression 즉 애스펙트J가 제공하는 포인트컷 표현식을 줄여서 말하는 것이다 1. 포인트컷 지시자 포인트컷 표현식은 execution 같은 포인트컷 지시자(Pointcut Designator)로 시작한다. 줄여서 PCD라 한다. execution : 메소드 실행 조인 포인트를 매칭한다. 스프링 AOP에서 가장 많이 사용하고, 기능도 복잡하다. within : 특정 타입 내의 조인 포인트를 매칭한다. args : 인자가 주어진 타입의 인스턴스인 조인 포인트 this : 스프링 빈 객체(스..
어드바이스는 앞서 살펴본 @Around 외에도 여러가지 종류가 있다. 1. Advice종류 @Around : 메서드 호출 전후에 수행, 가장 강력한 어드바이스, 조인 포인트 실행 여부 선택, 반환 값 변환, 예외 변환 등이 가능 ->모든 것을 할 수 있음. @Before : 조인 포인트 실행 이전에 실행 @AfterReturning : 조인 포인트가 정상 완료후 실행 @AfterThrowing : 메서드가 예외를 던지는 경우 실행 @After : 조인 포인트가 정상 또는 예외에 관계없이 실행(finally) 2. AspectV6 @Slf4j @Aspect public class AspectV6Advice { /* //hello.aop.order 패키지와 하위 패키지이면서, 클래스 이름 패턴이 *Servi..
어드바이스는 기본적으로 순서를 보장하지 않는다. 순서를 지정하고 싶으면 @Aspect 적용 단위로 org.springframework.core.annotation.@Order 애노테이션을 적용필요. 어드바이스 단위가 아니라 클래스 단위로 적용할 수 있다는 점이다. 그래서 지금처럼 하나의 애스펙트에 여러 어드바이스가 있으면 순서를 보장 받을 수 없다. 따라서 애스펙트를 별도의 클래스로 분리해야 한다. 로그를 남기는 순서를 바꾸어서 [ doTransaction() doLog() ] 트랜잭션이 먼저 처리되고, 이후에 로그가 남도록 변경해보자. 1. AspectV5 @Slf4j public class AspectV5Order { @Aspect @Order(2) public static class LogAspec..