將1.5.9.RELEASE版本的Spring Boot 項目添加 Spring Cloud依賴后,以下方法報錯
```
public static Object getJdkDynamicProxyTargetObject(Object proxy) throws Exception {
Field h = proxy.getClass().getSuperclass().getDeclaredField("h");
h.setAccessible(true);
AopProxy aopProxy = (AopProxy) h.get(proxy);
Field advised = aopProxy.getClass().getDeclaredField("advised");
advised.setAccessible(true);
Object target = ((AdvisedSupport)advised.get(aopProxy)).getTargetSource().getTarget();
return target;
}
```
該方法是獲取jdk動態代理機制的目標對象。引入Spring Cloud依賴后,Spring Boot 自動切換為cglib機制了,此方法不能獲取到目標對象。
解決方案為:強制指定Spring Boot的代理機制為jdk動態代理,在yml文件中,增加以下配置
```
spring:
aop:
proxy-target-class: false
```