TarsJava icon indicating copy to clipboard operation
TarsJava copied to clipboard

TarsClient注解的Prx对象初始化失败

Open kikoroc opened this issue 4 years ago • 1 comments

在Controller中通过@TarsClient注入其他服务的代理对象:

    @TarsClient(name = "xx.XxServer.XxObj", asyncTimeout = 10*1000)
    private UserPrx userPrx;

Controller在启动初始化时报错:

[TARS]  start application fail Error creating bean with name 'xxController': Unsatisfied dependency expressed through field ; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '' defined in file : Initialization of bean failed; nested exception is com.qq.tars.rpc.exc.CommunicatorConfigException: |error occurred on create proxy, servant endpoint is empty! locator =|communicator id=585e1bc33a5a4766aa7e4c92f0dbbda0
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name '': Unsatisfied dependency expressed through field ''; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '' defined in file : Initialization of bean failed; nested exception is com.qq.tars.rpc.exc.CommunicatorConfigException: |error occurred on create proxy, servant endpoint is empty! locator =|communicator id=585e1bc33a5a4766aa7e4c92f0dbbda0
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:587)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:373)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1350)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:580)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name : Initialization of bean failed; nested exception is com.qq.tars.rpc.exc.CommunicatorConfigException: error occurred on create proxy, servant endpoint is empty! locator =|communicator id=585e1bc33a5a4766aa7e4c92f0dbbda0
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:589)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:584)
	... 17 more
Caused by: com.qq.tars.rpc.exc.CommunicatorConfigException: error occurred on create proxy, servant endpoint is empty! locator =|communicator id=585e1bc33a5a4766aa7e4c92f0dbbda0
	at com.qq.tars.client.ObjectProxyFactory.updateServantEndpoints(ObjectProxyFactory.java:162)
	at com.qq.tars.client.ObjectProxyFactory.getObjectProxy(ObjectProxyFactory.java:62)
	at com.qq.tars.client.ServantProxyFactory.getServantProxy(ServantProxyFactory.java:49)
	at com.qq.tars.client.Communicator.stringToProxy(Communicator.java:82)
	at com.qq.tars.client.Communicator.stringToProxy(Communicator.java:68)
	at com.qq.tars.spring.bean.CommunicatorBeanPostProcessor.processFields(CommunicatorBeanPostProcessor.java:86)
	at com.qq.tars.spring.bean.CommunicatorBeanPostProcessor.postProcessBeforeInitialization(CommunicatorBeanPostProcessor.java:43)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:424)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1700)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:581)
	... 26 more

Process finished with exit code -1

在生成UserPrx代理对象时,此时UserServer可能还未启动,所以TarsClientBeanPostProcessor.processFieldsObject proxy = communicator.stringToProxy(field.getType(), config);更新UserServer节点时因为节点为空而报错,导致注入失败。

如果UserServer启动的情况下,再启动本服务的话是正常的。但是服务之间的启动顺序是无法保证的,而且可能存在互相依赖的情况。是否可以将代理对象改为延迟加载,比如调用的时候才加载?

kikoroc avatar May 11 '21 07:05 kikoroc

这是一个好的办法 。可以在服务真正使用的时候 ,延迟加载

TimmyYu avatar Jan 27 '22 14:01 TimmyYu