0
나는 몇 가지 클래스의 프록시 객체를 생성하기 위해 CGLIB를 사용하고, 물론cglib를 사용하여 사용자 정의 필드로 프록시를 생성하는 방법은 무엇입니까?
String customFieldName = "myCustomField";
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(targetClass);
// What can I do to add custom field to the proxy class ?
enhancer.setCallback(new MethodInterceptor() {
@Override
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
// I'd access the custom field value here
Field field = obj.getClass().getField(customFieldName);
Object customFieldValue = field.get(obj);
// do something
return proxy.invokeSuper(obj, args);
}
});
아래 그림처럼 나는 대안에 값을 바인딩지도를 사용하고있는 프록시 객체에 대한 일부 손님 필드를 바인드해야 원본 개체가 있지만 나는 이것을 정말로하고 싶지 않습니다.
아무도 아이디어가 있습니까?