NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
将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 ```