@RestController public class TestController { @Autowired private ConsulRetryRegistry consulRetryRegistry; @RequestMapping("server/offline") public String doDeRegister(){ ConsulRetryRegistry singletonTarget =(ConsulRetryRegistry) AopProxyUtils.getSingletonTarget(consulRetryRegistry); singletonTarget.retryThread.doRegister(); return "ok"; } }
注意:当直接注入ConsulRetryRegistry时,注入的是代理类,而代理类中的 retryThread属性字段是空的,所以需要获取被代理类,通过spring自带的util: AopProxyUtils
标签:spring,代理,获取,singletonTarget,retryThread,ConsulRetryRegistry From: https://www.cnblogs.com/yangxiaohui227/p/17141784.html