ํฌ์ธํธ์ปท ์ง์์ (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: ์ ๋ฌ๋ ์ค์ ์ธ์์ ๋ฐํ์ ์์ ํ์
์ด, ์ฃผ์ด์ง ํ์
์ ์ ๋
ธํ
์ด์
์ ๊ฐ๋ ์กฐ์ธ ํฌ์ธํธ๋ฅผ ๋งค์นญํฉ๋๋ค.
- ๋ค์์ ์ฐธ๊ณ - (https://ttl-blog.tistory.com/876)
- @within: ์ฃผ์ด์ง ์ ๋
ธํ
์ด์
์ด ์๋ ํ์
๋ด ์กฐ์ธ ํฌ์ธํธ๋ฅผ ๋งค์นญํฉ๋๋ค.
- ๋ค์์ ์ฐธ๊ณ - (https://ttl-blog.tistory.com/874)
- @annotation: ๋ฉ์๋๊ฐ ์ฃผ์ด์ง ์ ๋ ธํ ์ด์ ์ ๊ฐ์ง๊ณ ์๋ ์กฐ์ธ ํฌ์ธํธ๋ฅผ ๋งค์นญํฉ๋๋ค.
- bean : ์คํ๋ง ์ ์ฉ ํฌ์ธํธ์ปท ์ง์์๋ก, ๋น์ ์ด๋ฆ์ผ๋ก ํฌ์ธํธ์ปท์ ์ง์ ํฉ๋๋ค.
- ๋ค์์ ์ฐธ๊ณ - (https://ttl-blog.tistory.com/877)
@annotation
๋ฉ์๋๊ฐ, ์ฃผ์ด์ง(@annotation ์์ ์์ฑ๋) ์ ๋ ธํ ์ด์ ์ ๊ฐ์ง๊ณ ์๋ ์กฐ์ธ ํฌ์ธํธ๋ฅผ ๋งค์นญํฉ๋๋ค.
์๋ฅผ ๋ค์ด @annotation(hello.advanced.aop.member.anno.MethodAop) ๋ค์๊ณผ ๊ฐ์ ๊ฒฝ์ฐ
์ด๋ ํ ๋ฉ์๋์ @MethodAop๊ฐ ๋ถ์ด์๋ ๊ฒฝ์ฐ ์คํ๋ฉ๋๋ค.
์์ ์ฝ๋
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.MethodAop
import org.springframework.stereotype.Component
@Component
class MemberServiceImpl : MemberService{
@MethodAop("test value")
override fun hello(param: String): String {
return "ok"
}
fun internal(param: String): String {
return "ok"
}
}
@SpringBootTest
class AtAnnotationTest {
@Autowired
lateinit var memberService: MemberService
@Test
fun success() {
println("memberService Proxy={${memberService.javaClass}}")
memberService.hello("helloA")
}
}
@Aspect
@Component
class AtAnnotationAspect {
@Around("@annotation(hello.advanced.aop.member.anno.MethodAop)")
fun doAtAnnotation(joinPoint: ProceedingJoinPoint): Any? {
println("[@annotation] {${joinPoint.signature}}")
return joinPoint.proceed()
}
}
๋ค์๊ณผ ๊ฐ์ ๊ฒฝ์ฐ์๋ ์ ์ฉ๋์ง ์์ต๋๋ค.
interface MemberService {
@MethodAop("test value")
fun hello(param: String): String
}
@Component
class MemberServiceImpl : MemberService{
override fun hello(param: String): String {
return "ok"
}
fun internal(param: String): String {
return "ok"
}
}
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 ํฌ์ธํธ์ปท ํํ์ (8) - bean (0) | 2022.08.02 |
---|---|
[AOP] AOP ํฌ์ธํธ์ปท ํํ์ (7) - @args (0) | 2022.08.02 |
[AOP] AOP ํฌ์ธํธ์ปท ํํ์ (5) - @within (0) | 2022.08.02 |
[AOP] AOP ํฌ์ธํธ์ปท ํํ์ (4) - @target (0) | 2022.08.02 |
[AOP] AOP ํฌ์ธํธ์ปท ํํ์ (3) - args (0) | 2022.08.02 |