ํฌ์ธํธ์ปท ์ง์์ (Pointcut Designators)
์คํ๋ง์์๋ ํฌ์ธํธ์ปท ํํ์์์ ์ฌ์ฉํ๊ธฐ ์ํด ๋ค์ AspectJ ํฌ์ธํธ์ปท ์ง์์(PCD)๋ฅผ ์ง์ํฉ๋๋ค.
- execution: ๋ฉ์๋ ์คํ ์กฐ์ธ ํฌ์ธํธ๋ฅผ ๋งค์นญํฉ๋๋ค.
- ์คํ๋ง AOP์์ ๊ฐ์ฅ ๋ง์ด ์ฌ์ฉํฉ๋๋ค.
- ๋ค์์ ์ฐธ๊ณ - (https://ttl-blog.tistory.com/870)
- within: ํน์ ํ ํ์
๋ด์ ์กฐ์ธ ํฌ์ธํธ๋ฅผ ๋งค์นญํฉ๋๋ค.
- ๋ถ๋ชจ ํ์ ์ ์ง์ ํ๋ฉด ์ ์ฉ๋์ง ์์ต๋๋ค.
- ๋ค์์ ์ฐธ๊ณ - (https://ttl-blog.tistory.com/871)
- this: ์คํ๋ง ๋น ๊ฐ์ฒด(์คํ๋ง AOP ํ๋ก์)๋ฅผ ๋์์ผ๋ก ํ๋ ์กฐ์ธ ํฌ์ธํธ๋ฅผ ๋งค์นญํฉ๋๋ค.
- ๋ค์์ ์ฐธ๊ณ - (https://ttl-blog.tistory.com/878)
- target: target ๊ฐ์ฒด(์คํ๋ง AOP ํ๋ก์๊ฐ ๊ฐ๋ฆฌํค๋ ์ค์ ๋์)๋ฅผ ๋์์ผ๋ก ํ๋ ์กฐ์ธ ํฌ์ธํธ๋ฅผ ๋งค์นญํฉ๋๋ค.
- ๋ค์์ ์ฐธ๊ณ - (https://ttl-blog.tistory.com/879)
- args: ์ธ์๊ฐ, ์ฃผ์ด์ง ํ์
์ ์ธ์คํด์ค์ธ ์กฐ์ธ ํฌ์ธํธ๋ฅผ ๋งค์นญํฉ๋๋ค.
- ๋ค์์ ์ฐธ๊ณ - (https://ttl-blog.tistory.com/872)
- @target: ์คํ ๊ฐ์ฒด์ ํด๋์ค์, ์ฃผ์ด์ง ํ์
์ ์ ๋
ธํ
์ด์
์ด ์๋ ์กฐ์ธ ํฌ์ธํธ๋ฅผ ๋งค์นญํฉ๋๋ค.
- ๋ค์์ ์ฐธ๊ณ - (https://ttl-blog.tistory.com/873)
- @args: ์ ๋ฌ๋ ์ค์ ์ธ์์ ๋ฐํ์ ์์ ํ์ ์ด, ์ฃผ์ด์ง ํ์ ์ ์ ๋ ธํ ์ด์ ์ ๊ฐ๋ ์กฐ์ธ ํฌ์ธํธ๋ฅผ ๋งค์นญํฉ๋๋ค.
- @within: ์ฃผ์ด์ง ์ ๋
ธํ
์ด์
์ด ์๋ ํ์
๋ด ์กฐ์ธ ํฌ์ธํธ๋ฅผ ๋งค์นญํฉ๋๋ค.
- ๋ค์์ ์ฐธ๊ณ - (https://ttl-blog.tistory.com/874)
- @annotation: ๋ฉ์๋๊ฐ ์ฃผ์ด์ง ์ ๋
ธํ
์ด์
์ ๊ฐ์ง๊ณ ์๋ ์กฐ์ธ ํฌ์ธํธ๋ฅผ ๋งค์นญํฉ๋๋ค.
- ๋ค์์ ์ฐธ๊ณ - (https://ttl-blog.tistory.com/875)
- bean : ์คํ๋ง ์ ์ฉ ํฌ์ธํธ์ปท ์ง์์๋ก, ๋น์ ์ด๋ฆ์ผ๋ก ํฌ์ธํธ์ปท์ ์ง์ ํฉ๋๋ค.
- ๋ค์์ ์ฐธ๊ณ - (https://ttl-blog.tistory.com/877)
@args
์ ๋ฌ๋ ์ค์ ์ธ์์ ๋ฐํ์ ํ์ ์ด ์ฃผ์ด์ง(@args์ ์์ฑ๋) ์ ๋ ธํ ์ด์ ์ ๊ฐ๋ ๊ฒฝ์ฐ์ ๋งค์นญํฉ๋๋ค.
์์ ์ฝ๋
package hello.advanced.aop.member.anno
import kotlin.annotation.AnnotationRetention.RUNTIME
import kotlin.annotation.AnnotationTarget.*
@Target(CLASS)//ํด๋์ค์ ๋ถ์
@Retention(RUNTIME)
annotation class ClassAop()
ํด๋์ค์ ์ฌ์ฉํ ์ด๋ ธํ ์ด์ ์ ๋๋ค.
package hello.advanced.aop.member.anno
import kotlin.annotation.AnnotationRetention.*
import kotlin.annotation.AnnotationTarget.*
@Target(FUNCTION)
@Retention(RUNTIME)
annotation class MethodAop(
val value: String
)
๋ฉ์๋์ ์ฌ์ฉํ ์ด๋ ธํ ์ด์ ์ ๋๋ค.
package hello.advanced.aop.member
interface MemberService {
fun hello(param: String): String
}
package hello.advanced.aop.member
import hello.advanced.aop.member.anno.ClassAop
import hello.advanced.aop.member.anno.MethodAop
import org.springframework.stereotype.Component
@ClassAop
@Component
class MemberServiceImpl : MemberService{
@MethodAop("test value")
override fun hello(param: String): String {
return "ok"
}
fun internal(param: String): String {
return "ok"
}
}
package hello.advanced.pointcut
import org.aspectj.lang.ProceedingJoinPoint
import org.aspectj.lang.annotation.Around
import org.aspectj.lang.annotation.Aspect
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.stereotype.Component
import kotlin.annotation.AnnotationRetention.RUNTIME
import kotlin.annotation.AnnotationTarget.CLASS
@SpringBootTest
class AtArgsTest {
@Autowired
lateinit var foo: Foo
@Autowired
lateinit var boo: Boo
@Test
fun success() {
println("memberService Proxy={${foo.javaClass}}")
foo.fooBoo(boo)
}
}
@Aspect
@Component
class AtArgsAspect {
@Around("execution(* hello.advanced..*(..)) && @args(hello.advanced.pointcut.ArgsAop)")
fun doLog(joinPoint: ProceedingJoinPoint): Any? {
println("[@args] {${joinPoint.signature}}")
return joinPoint.proceed()
}
}
@Target(CLASS)
@Retention(RUNTIME)
annotation class ArgsAop
@Component
class Foo {
fun fooBoo(boo: Boo) {
println("Foo")
}
}
@ArgsAop
@Component
class Boo {}
์ฃผ์์ฌํญ - args, @args, @target
args, @args, @target
์ ์ธ ํฌ์ธํธ์ปท ์ง์์๋ ๋จ๋ ์ผ๋ก ์ฌ์ฉํ๋ฉด ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
execution๋ฑ๊ณผ ํจ๊ป ์ฌ์ฉํ์ฌ ์ ์ฉ ๋์์ ์ค์ฌ์ฃผ์ด์ผ ํฉ๋๋ค.
args, @args, @target๋ ์ค์ ๊ฐ์ฒด ์ธ์คํด์ค๊ฐ ์์ฑ๋๊ณ ์คํ๋ ๋ ์ด๋๋ฐ์ด์ค ์ ์ฉ ์ฌ๋ถ๋ฅผ ํ์ธํ ์ ์์ต๋๋ค.
์คํ ์์ ์ ์ผ์ด๋๋ ํฌ์ธํธ์ปท ์ฌ๋ถ๋ ๊ฒฐ๊ตญ์ ํ๋ก์๊ฐ ์์ด์ผ ํ๋จ์ด ๊ฐ๋ฅํฉ๋๋ค.
๊ทธ๋ฐ๋ฐ ์คํ๋ง ์ปจํ ์ด๋๊ฐ ํ๋ก์๋ฅผ ์์ฑํ๋ ์์ ์ ์คํ๋ง ์ปจํ ์ด๋๊ฐ ๋ง๋ค์ด์ง๋ ์ ํ๋ฆฌ์ผ์ด์ ๋ก๋ฉ ์์ ์ ์ ์ฉํ ์ ์์ต๋๋ค.
๋ฐ๋ผ์ args, @args, @target๊ฐ์ ํฌ์ธํธ์ปท ์ง์์๊ฐ ์์ผ๋ฉด, ์คํ๋ง์ ๋ชจ๋ ์คํ๋ง ๋น์ AOP๋ฅผ ์ ์ฉํ๋ ค ์๋ํฉ๋๋ค.
์์ ์ค๋ช ํ ๊ฒ ์ฒ๋ผ, ํ๋ก์๊ฐ ์์ผ๋ฉด ์คํ ์์ ์ ํ๋จ ์์ฒด๊ฐ ๋ถ๊ฐ๋ฅํ๊ธฐ ๋๋ฌธ์ ๋๋ค.
๋ชจ๋ ์คํ๋ง ๋น์ AOP๋ฅผ ์ ์ฉํ๋ ค ํ๊ธฐ ๋๋ฌธ์, ์ ์ฉ ๋ฒ์๋ฅผ ์ค์ฌ์ฃผ์ง ์์ผ๋ฉด ์คํ๋ง์ด ๋ด๋ถ์ ์ผ๋ก ์ฌ์ฉํ๊ธฐ ์ํด ๋ฑ๋กํ๋ ค๋ ๋น๋ค ์ค final๋ก ์ง์ ๋ ๋น๋ค์ด ๋ฑ๋ก๋ ๋ ํ๋ก์๋ฅผ ๋ง๋ค์ง ๋ชปํด ์ค๋ฅ๊ฐ ๋ฐ์ํ ์ ์์ต๋๋ค.
๋ฐ๋ผ์ args, @args, @target๋ ๋ค๋ฅธ ํฌ์ธํธ์ปท ํํ์๊ณผ ํจ๊ป ์ฌ์ฉํ์ฌ์ผ ํฉ๋๋ค.
Reference
https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#aop-pointcuts
Core Technologies
In the preceding scenario, using @Autowired works well and provides the desired modularity, but determining exactly where the autowired bean definitions are declared is still somewhat ambiguous. For example, as a developer looking at ServiceConfig, how do
docs.spring.io
์คํ๋ง ํต์ฌ ์๋ฆฌ - ๊ณ ๊ธํธ - ์ธํ๋ฐ | ๊ฐ์
์คํ๋ง์ ํต์ฌ ์๋ฆฌ์ ๊ณ ๊ธ ๊ธฐ์ ๋ค์ ๊น์ด์๊ฒ ํ์ตํ๊ณ , ์คํ๋ง์ ์์ ์๊ฒ ์ฌ์ฉํ ์ ์์ต๋๋ค., - ๊ฐ์ ์๊ฐ | ์ธํ๋ฐ...
www.inflearn.com
'๐๏ธ Spring > AOP' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[AOP] AOP ํฌ์ธํธ์ปท ํํ์ (9) - this (0) | 2022.08.02 |
---|---|
[AOP] AOP ํฌ์ธํธ์ปท ํํ์ (8) - bean (0) | 2022.08.02 |
[AOP] AOP ํฌ์ธํธ์ปท ํํ์ (6) - @annotation (0) | 2022.08.02 |
[AOP] AOP ํฌ์ธํธ์ปท ํํ์ (5) - @within (0) | 2022.08.02 |
[AOP] AOP ํฌ์ธํธ์ปท ํํ์ (4) - @target (0) | 2022.08.02 |