Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
back-end:spring [2022/06/19 16:33] – [Pointcut Designators] execution 예제 추가 ledyxback-end:spring [2024/10/14 01:35] (current) – [Lifecycle Callbacks] ledyx
Line 65: Line 65:
 </sxh> </sxh>
  
-  * 메서드를 구현하고 @PostConstruct, @PostDestroy 사용. (Java 표준) => 추천!+  * 메서드를 구현하고 @PostConstruct, @PreDestroy 사용. (Java 표준) => 추천!
  
  
Line 99: Line 99:
         client-- request -->ProxyFactory         client-- request -->ProxyFactory
         ProxyFactory-- Proxy 대상 객체가 Interface를 구현 O -->p1[JDK dynamic proxy]         ProxyFactory-- Proxy 대상 객체가 Interface를 구현 O -->p1[JDK dynamic proxy]
-        ProxyFactory-- Proxy 대상 객체가 Interface를 구현 X -->p2[CGLIB proxy]+        ProxyFactory-- Proxy 대상 객체가 Interface를 구현 X<br>Target Class를 상속 -->p2[CGLIB proxy]
         p1-- "call" -->a["Advice\n(추상화)"]         p1-- "call" -->a["Advice\n(추상화)"]
         p2-- "call" -->a["Advice\n(추상화)"]         p2-- "call" -->a["Advice\n(추상화)"]
Line 151: Line 151:
   * [[#Pointcut]] 대상/후보라고도 한다.   * [[#Pointcut]] 대상/후보라고도 한다.
  
-==== Pointcut ====+=== Pointcut ===
   * Filtering 된 [[#Joinpoint]].   * Filtering 된 [[#Joinpoint]].
   * 수많은 Business Method 중에서 원하는 특정 Method에서만 [[#Cross-cutting Concern | 횡단 관심]]에 해당하는 공통 기능 수행.   * 수많은 Business Method 중에서 원하는 특정 Method에서만 [[#Cross-cutting Concern | 횡단 관심]]에 해당하는 공통 기능 수행.
   * **Advice가 적용될 __<fc red>위치</fc>__, __<fc red>Filter Logic</fc>__**   * **Advice가 적용될 __<fc red>위치</fc>__, __<fc red>Filter Logic</fc>__**
  
-===== Pointcut Designators =====+==== Pointcut Designators ====
  
 [[https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#aop-pointcuts-designators|Supported Pointcut Designators]] [[https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#aop-pointcuts-designators|Supported Pointcut Designators]]
Line 163: Line 163:
  
   * execution : Method 실행 join points를 matching. Spring AOP로 작업할 때 가장 우선적인 PCD이다.   * execution : Method 실행 join points를 matching. Spring AOP로 작업할 때 가장 우선적인 PCD이다.
-  * within : 특정 Type에 join points를 matching+    * declaring-type-pattern에서 부모 타입 가능 
-  this : Spring 빈 객체(Spring AOP Proxy)를 대상 +    * param-pattern에서 부모 타입 불가능 
-  * target : target 객체(Spring AOP Porxy가 적용되는 실제 객체)를 대상으로 하는 joinpoints+ 
 +  * within : 특정 Type에 join points 적용
 +    부모 타입 불가능. 정확히 맞아야 한다. 
 +  * target : target 객체(Spring AOP Porxy가 적용되는 __실제 객체__)를 대상으로 하는 join points 적용 
 +    * 부모 타입 가능. 
 +  * this : Spring 빈 객체(Spring AOP __Proxy__)를 대상 
 +    * 부모 타입 가능. 
   * args : 인자가 주어진 타입의 인스턴스 한정   * args : 인자가 주어진 타입의 인스턴스 한정
-  @target : 실행 객체의 Class에 지정된 Type의 Annotation이 있는 Join points. +    부모 타입 
-  * @args : 전달된 실제 arguments의 Runtime type이 주어진 Type의 Annotation이 있는 Join points +
-  * @annotation : Method가 주어진 Annotation을 갖고 있는 Join points에 matching.+
  
  
-====== Example ======+  * @target : Annotation이 있는 Type에서 부모 타입을 허용하여 모든 Method에 join points 적용 
 +  * @within : Annotation이 있는 Type 내에 있는 Method에 join points 적용. (부모 타입 불가) 
 + 
 +  * @args : 전달된 실제 arguments의 Runtime type이 주어진 Type의 Annotation이 있는 Join points 적용 
 +    * 부모 타입 허용 
 +  * @annotation : Method가 주어진 Annotation을 갖고 있는 Join points 적용. 
 + 
 +<note important> 
 +**args, @args, @target**는 단독으로 사용하면 안된다! 
 +이 PCD들은 인스턴스가 만들어진 후 Runtime 시점에서 동작한다. 
 +그러므로 단독으로 사용하면 모든 스프링 빈에 AOP를 적용하려고 시도한다. 
 +이 때, 스프링 내부에서 사용하는 빈 중에 'final'로 지정된 빈이 있어서 오류가 발생한다. 
 +</note> 
 + 
 +===== execution =====
  
   * [[https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#aop-pointcuts-examples|Official]]   * [[https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#aop-pointcuts-examples|Official]]
   *[[https://www.baeldung.com/spring-aop-pointcut-tutorial|Baeldang]]   *[[https://www.baeldung.com/spring-aop-pointcut-tutorial|Baeldang]]
 +
 +  * Pattern
 +    * **<nowiki>*</nowiki>** : 1개
 +    * **..** : 0..n개
  
 <code> <code>
 execution(modifiers-pattern? ret-type-pattern declaring-type-pattern?name-pattern(param-pattern)) execution(modifiers-pattern? ret-type-pattern declaring-type-pattern?name-pattern(param-pattern))
 +</code>
  
-// 예시+<sxh java ; gutter:false>
 execution(public app.domain.Member app.repository.Repository.findById(String)) execution(public app.domain.Member app.repository.Repository.findById(String))
-  - modifiers-pattern : public 
-  - ret-type-pattern : app.domain.Member 
-  - declaring-type-pattern : app.repository.Repository 
-  - name-pattern : findById 
-  - param-pattern : String 
-</code> 
  
-  * Pattern +//  - modifiers-pattern public 
-    * **<nowiki>*</nowiki>** 1개 +//  - ret-type-pattern : app.domain.Member 
-    * **..** 0..n개+//  - declaring-type-pattern app.repository.Repository 
 +//  - name-pattern : findById 
 +//  - param-pattern : String 
 +</sxh>
  
  
back-end/spring.1655652810.txt.gz · Last modified: 2022/06/19 16:33 by ledyx