I'd had a similar problem like yours. I'd wanted to write log my repository name at a method of AOP.
When I tried with ClassUtils.getUserClass()
from upper James' answer, my aop method write log as same as before.
I solved the problem with AopProxyUtils.getSingletonTarget()
.
Plus, I leave following cases for someone who will have same problem.
@SpringBootTest
class AopLoggingServiceTest {
@Autowired
TestRepository testRepository;
public void someAopMethod(){
Class<?> try1 = AopUtils.getTargetClass(testRepository);
System.out.println("AopUtils.getTargetClass : " + try1);
Class<?> try2 = ClassUtils.getUserClass(testRepository);
System.out.println("ClassUtils.getUserClass : " + try2);
Class<?> try3 = AopProxyUtils.ultimateTargetClass(testRepository);
System.out.println("AopProxyUtils.ultimateTargetClass : " + try3);
Class<?> finalTry = AopProxyUtils.proxiedUserInterfaces(testRepository)[0];
System.out.println ("AopProxyUtils.proxiedUserInterfaces[0] : " + finalTry);
}
}
outputs :
AopUtils.getTargetClass : class com.sun.proxy.$Proxy172
AopProxyUtils.ultimateTargetClass : class org.springframework.data.jpa.repository.support.SimpleJpaRepository
ClassUtils.getUserClass : class com.sun.proxy.$Proxy172
AopProxyUtils.proxiedUserInterfaces[0] : interface io.juyeon.test.repository.TestRepository