2
인터셉터에서 어떻게 목표물을 얻을 수 있습니까?MethodInterceptor에서 타겟 얻기
bindInterceptor(subclassesOf(A.class), any(), new MethodInterceptor() {
@Override
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
A a = getTarget(); //how?
return methodInvocation.proceed();
}
});
UPD 사실,이 반사 기반 솔루션이지만, 거기에 다른 솔루션 ..
private static Object getTarget(MethodInvocation methodInvocation) throws NoSuchFieldException, IllegalAccessException {
return getFieldValue(methodInvocation, "proxy");
}
private static Object getFieldValue(Object obj, String field) throws NoSuchFieldException, IllegalAccessException {
Field f = obj.getClass().getDeclaredField(field);
f.setAccessible(true);
return f.get(obj);
}
Yeap. 고마워. 내 인터셉터에 몇 가지 버그가 있었고 잘못된 객체를 반환하는 데 사용 된'getThis()'가있었습니다. 이제는 잘 작동합니다. 감사. –