Spring AOP - Self Invocation
@Cacheable self-invocation (in effect, a method within the target object calling another method of the target object).
The cache annotation will be ignored at runtime
μ€νλ§ νλ μμν¬μμ κ°λ°μκ° κ²½ννκΈ° μ¬μ΄ μ€μλ λμΌν ν΄λμ€ λ΄μμ λΉλκΈ° λλ μΊμ μ΄λ Έν μ΄μ μ΄ μ μΈλ ν¨μλ₯Ό λ΄λΆμ μΌλ‘ νΈμΆνλλ‘ λΉμ¦λμ€ λ‘μ§μ μμ±νλ κ² μ λλ€. μ΄λ¬ν λ¬Έμ κ° λ°μνλ κ²½μ°μλ Self Invocationμ΄ λμ§ μλλ‘ λ³λμ ν΄λμ€λ‘ λΆλ¦¬λλλ‘ λ¦¬ν©ν λ§μ μ§ννκ±°λ Self-Injectionμ΄ λλλ‘ μμ ν΄μΌν©λλ€. κ·ΈμΈμ μλμ κ°μ λ°©λ²λ€λ μμ§λ§ μ νΈλμ§ μμ΅λλ€.
@Service
public class AService extends AbstractService {
@Cacheable(cacheNames = "a", key = "#root.methodName", unless = "#result == null")
public String getA() {
return "A";
}
public String getAA() {
return ((AService) AopContext.currentProxy()).getA();
}
}
- AdviceMode.ASPECTJ (AspectJ Weaving)
- AopContext.currentProxy()
- ApplicationContext.getBean()
μ€νλ§ νλ μμν¬ κΈ°λ°μ μ ν리μΌμ΄μ μλ²λ₯Ό μμ±νλ κ°λ°μλΌλ©΄ νλ‘μ 맀컀λμ¦μ λν΄μ μ΄ν΄νκ³ μμ΄μΌ ν©λλ€. κΈ°λ³Έμ μΈ νλ‘μ(CGLib) λλ JDK νλ‘μκ° λ¬΄μμΈμ§ μκ³ μμ΄μΌ μ public μ κ·Όμ μ΄μκ° μλκ±°λ λ΄λΆ νΈμΆμΈ κ²½μ° AOPλ₯Ό μνν μ μλμ§λ₯Ό μ΄ν΄ν μ μμ΅λλ€.