Java·ο»ΏServlet·ο»ΏJSP/Library·Framework

[AspectJ Weaver] execution μ§€μ‹œμž μ„€μ • 방법 정리

Leica 2020. 4. 27. 22:35
λ°˜μ‘ν˜•

[AspectJ Weaver] execution μ§€μ‹œμž μ„€μ • λ°©λ²• μ •λ¦¬

Execution μ§€μ‹œμž


Execution μ§€μ‹œμž μ„€μ • 방법

- Pointcut을 지정할 λ•Œ μ‚¬μš©ν•˜λŠ” 문법
- ν˜•μ‹ : execution(λ¦¬ν„΄νƒ€μž… ν΄λž˜μŠ€μ΄λ¦„ λ©”μ†Œλ“œμ΄λ¦„(λ§€κ°œλ³€μˆ˜))
- λ¦¬ν„΄νƒ€μž… ➑️ λ©”μ†Œλ“œμ˜ 리턴 νƒ€μž…
- 클래슀 이름 ➑️ νŒ¨ν‚€μ§€λ₯Ό ν¬ν•¨ν•œ 클래슀 이름 / νŒ¨ν‚€μ§€ μƒλž΅ μ‹œ λͺ¨λ“  νŒ¨ν‚€μ§€ / 클래슀 μƒλž΅ μ‹œ λͺ¨λ“  클래슀
- λ©”μ†Œλ“œ 이름 ➑️ λ©”μ†Œλ“œμ˜ 이름
- λ§€κ°œλ³€μˆ˜ ➑️ λ§€κ°œλ³€μˆ˜μ˜ ν˜•νƒœ

μ™€μΌλ“œμΉ΄λ“œ

* ➑️ ν•˜λ‚˜μ˜ λͺ¨λ“  것을 의미
.. ➑️ 개수 상관없이 λͺ¨λ“  것을 의미

예) execution(void com.atoz_develop.beans.TestBean1.method1())
➑️ λ¦¬ν„΄νƒ€μž… void, com.atoz_develop.beans.TestBean1 클래슀, method1 λ©”μ†Œλ“œ, λ§€κ°œλ³€μˆ˜ μ—†μŒ

execution μ§€μ‹œμžλŠ” AspectJ Weaverλ₯Ό μ‚¬μš©ν•΄μ„œ μŠ€ν”„λ§ AOPλ₯Ό κ΅¬ν˜„ν• λ•Œ PointCut을 μ„€μ •ν•˜κΈ° μœ„ν•΄ μ‚¬μš©ν•œλ‹€.

μ„€μ •λœ PointCut이 λ™μž‘ν• λ•Œ μŠ€ν”„λ§μ΄ 이λ₯Ό κ°€λ‘œμ±„μ„œ μ§€μ •λœ adviceκ°€ μœ„λΉ™λ˜λ„λ‘ ν•œλ‹€.

 

πŸ”— μ°Έκ³ 

AspectJ Weaverλ₯Ό μ‚¬μš©ν•œ XML 기반의 μŠ€ν”„λ§ AOP κ΅¬ν˜„ 방법

AspectJ Weaverλ₯Ό μ‚¬μš©ν•œ μ• λ…Έν…Œμ΄μ…˜ κΈ°λ°˜μ˜ μŠ€ν”„링 AOP κ΅¬ν˜„ λ°©λ²•

 

πŸ“ λ‹€μŒ 예제λ₯Ό ν…ŒμŠ€νŠΈν•œ AspectJ Weaver 버전은 1.9.4이닀.

 

예제 1

execution(void com.atoz_develop.beans.TestBean1.method1())

➑️ λ¦¬ν„΄νƒ€μž… void, com.atoz_develop.beans.TestBean1 클래슀, method1 λ©”μ†Œλ“œ, λ§€κ°œλ³€μˆ˜ μ—†μŒ

 

예제 2

execution(void com.atoz_develop.beans.TestBean1.method1(int))

➑️ λ¦¬ν„΄νƒ€μž… void, com.atoz_develop.beans.TestBean1 클래슀, method1 λ©”μ†Œλ“œ, int λ§€κ°œλ³€μˆ˜ 1개

 

예제 3

execution(void com.atoz_develop.beans.TestBean1.method1(java.lang.String))

➑️ λ¦¬ν„΄νƒ€μž… void, com.atoz_develop.beans.TestBean1 클래슀, method1 λ©”μ†Œλ“œ, String λ§€κ°œλ³€μˆ˜ 1개

 

예제 4

execution(void com.atoz_develop.beans.TestBean1.method1(*))

➑️ λ¦¬ν„΄νƒ€μž… void, com.atoz_develop.beans.TestBeans1 클래슀, method1 λ©”μ†Œλ“œ, λͺ¨λ“  νƒ€μž…μ˜ λ§€κ°œλ³€μˆ˜ 1개

 

예제 5

execution(void com.atoz_develop.beans.TestBean1.method1(int, int))

➑️ λ¦¬ν„΄νƒ€μž… void, com.atoz_develop.beans.TestBeans1 클래슀, method1 λ©”μ†Œλ“œ, int λ§€κ°œλ³€μˆ˜ 2개

 

예제 6

execution(void com.atoz_develop.beans.TestBean1.method1(int, java.lang.String))

➑️ λ¦¬ν„΄νƒ€μž… void, com.atoz_develop.beans.TestBeans1 클래슀, method1 λ©”μ†Œλ“œ, int λ§€κ°œλ³€μˆ˜ 1개, String λ§€κ°œλ³€μˆ˜ 1개

 

예제 7

execution(void com.atoz_develop.beans.TestBean1.method1(*, *))

➑️ λ¦¬ν„΄νƒ€μž… void, com.atoz_develop.beans.TestBeans1 클래슀, method1 λ©”μ†Œλ“œ, λͺ¨λ“  νƒ€μž…μ˜ λ§€κ°œλ³€μˆ˜ 2개

 

예제 8

execution(void com.atoz_develop.beans.TestBean1.method1(..))

➑️ λ¦¬ν„΄νƒ€μž… void, com.atoz_develop.beans.TestBeans1 클래슀, method1 λ©”μ†Œλ“œ, λͺ¨λ“  νƒ€μž…μ˜ λ§€κ°œλ³€μˆ˜ 0개 이상

μ΄λ ‡κ²Œ μ„€μ •ν•˜λ©΄ λ§€κ°œλ³€μˆ˜κ°€ μ—†λŠ” method1() λ©”μ†Œλ“œμ˜ ν˜ΈμΆœλ„ PointCut으둜 μ„€μ •λœλ‹€.

 

예제 9

execution(void com.atoz_develop.beans.TestBean1.*(..))

➑️ λ¦¬ν„΄νƒ€μž… void, com.atoz_develop.beans.TestBeans1 클래슀, λͺ¨λ“  λ©”μ†Œλ“œ

λͺ¨λ“  λ©”μ†Œλ“œλ₯Ό PointCut으둜 μ„€μ •ν• λ•Œ *(..)λ₯Ό μ‚¬μš©ν•œλ‹€.

 

예제 10

execution(void com.atoz_develop.beans.*.method1(..))

➑️ λ¦¬ν„΄νƒ€μž… void, com.atoz_develop.beans νŒ¨ν‚€μ§€μ˜ λͺ¨λ“  클래슀, method1 λ©”μ†Œλ“œ, λͺ¨λ“  νƒ€μž…μ˜ λ§€κ°œλ³€μˆ˜ 0개 이상

 

예제 11

execution(void com.atoz_develop.beans.*.*(..))

➑️ λ¦¬ν„΄νƒ€μž… void, com.atoz_develop.beans νŒ¨ν‚€μ§€μ˜ λͺ¨λ“  클래슀, λͺ¨λ“  λ©”μ†Œλ“œ

 

예제 12

execution(void com.atoz_develop.*.*.*(..))

➑️ λ¦¬ν„΄νƒ€μž… void, com.atoz_develop μ΄ν•˜μ˜ λͺ¨λ“  νŒ¨ν‚€μ§€μ˜ λͺ¨λ“  클래슀, λͺ¨λ“  λ©”μ†Œλ“œ

 

예제 13

execution(void *.*(..))

➑️ λ¦¬ν„΄νƒ€μž… void, λͺ¨λ“  νŒ¨ν‚€μ§€, λͺ¨λ“  클래슀, λͺ¨λ“  λ©”μ†Œλ“œ

νŒ¨ν‚€μ§€λ₯Ό μƒλž΅ν•˜λ©΄ λͺ¨λ“  νŒ¨ν‚€μ§€κ°€ λŒ€μƒμ΄ λœλ‹€.

 

예제 14

execution(int *.*(..))

➑️ λ¦¬ν„΄νƒ€μž… int, λͺ¨λ“  νŒ¨ν‚€μ§€, λͺ¨λ“  클래슀, λͺ¨λ“  λ©”μ†Œλ“œ

 

예제 15

execution(* *.*(..))

➑️ λͺ¨λ“  λ¦¬ν„΄νƒ€μž…, λͺ¨λ“  νŒ¨ν‚€μ§€, λͺ¨λ“  클래슀, λͺ¨λ“  λ©”μ†Œλ“œ

 

예제 16

execution(* method1(..))

➑️ λͺ¨λ“  λ¦¬ν„΄νƒ€μž…, λͺ¨λ“  νŒ¨ν‚€μ§€, λͺ¨λ“  클래슀, method1 λ©”μ†Œλ“œ, λͺ¨λ“  νƒ€μž…μ˜ λ§€κ°œλ³€μˆ˜ 0개 이상

클래슀λ₯Ό μƒλž΅ν•˜λ©΄ μ„€μ •ν•œ νŒ¨ν‚€μ§€μ˜ λͺ¨λ“  ν΄λž˜μŠ€κ°€ λŒ€μƒμ΄ λœλ‹€.

 

κ΄€λ ¨ κΈ€

- AspectJ Weaverλ₯Ό μ‚¬μš©ν•œ XML 기반의 μŠ€ν”„λ§ AOP κ΅¬ν˜„ 방법

- AspectJ Weaverλ₯Ό μ‚¬μš©ν•œ μ• λ…Έν…Œμ΄μ…˜ 기반의 μŠ€ν”„λ§ AOP κ΅¬ν˜„ 방법

 

References

μΈν”„λŸ° - μ†Œν”„νŠΈμΊ νΌμŠ€ μŠ€ν”„λ§ ν”„λ ˆμž„μ›Œν¬ 개발자λ₯Ό μœ„ν•œ μ‹€μŠ΅μ„ ν†΅ν•œ μž…λ¬Έ κ³Όμ •

λ°˜μ‘ν˜•