๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Java·๏ปฟServlet·๏ปฟJSP/Library·Framework

[AspectJ Weaver] execution ์ง€์‹œ์ž ์„ค์ • ๋ฐฉ๋ฒ• ์ •๋ฆฌ

by Leica 2020. 4. 27.
๋ฐ˜์‘ํ˜•

[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

์ธํ”„๋Ÿฐ - ์†Œํ”„ํŠธ์บ ํผ์Šค ์Šคํ”„๋ง ํ”„๋ ˆ์ž„์›Œํฌ ๊ฐœ๋ฐœ์ž๋ฅผ ์œ„ํ•œ ์‹ค์Šต์„ ํ†ตํ•œ ์ž…๋ฌธ ๊ณผ์ •

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€