spring core aop : proxy - internal call problem
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user