spring core aop : proxy - internal call problem

This commit is contained in:
haerong22
2021-11-28 03:59:25 +09:00
parent 03b2085dac
commit bcb52c0a18
3 changed files with 66 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
package com.example.aop.internalcall;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class CallServiceV0 {
/**
* 객체에서 내부 메소드를 호출 하는 경우 프록시가 적용 되지 않는 문제 발생
*/
public void external() {
log.info("call external");
internal();
}
public void internal() {
log.info("call internal");
}
}

View File

@@ -0,0 +1,16 @@
package com.example.aop.internalcall.aop;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
@Slf4j
@Aspect
public class CallLogAspect {
@Before("execution(* com.example.aop.internalcall..*.*(..))")
public void doLog(JoinPoint joinPoint) {
log.info("aop={}", joinPoint.getSignature());
}
}

View File

@@ -0,0 +1,29 @@
package com.example.aop.internalcall;
import com.example.aop.internalcall.aop.CallLogAspect;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;
import static org.junit.jupiter.api.Assertions.*;
@Slf4j
@Import(CallLogAspect.class)
@SpringBootTest
class CallServiceV0Test {
@Autowired
CallServiceV0 callServiceV0;
@Test
void external() {
callServiceV0.external();
}
@Test
void internal() {
callServiceV0.internal();
}
}