You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/07/19 05:39:52 UTC

[GitHub] [dubbo] linxiaobai commented on issue #8306: how to refer dubbo service in unit test

linxiaobai commented on issue #8306:
URL: https://github.com/apache/dubbo/issues/8306#issuecomment-882253799


   > Try this
   > 
   > ```
   > ReferenceConfig<DemoService> reference = new ReferenceConfig<>();
   > reference.setApplication(new ApplicationConfig("dubbo-demo-api-consumer"));
   > reference.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181"));
   > reference.setInterface(DemoService.class);
   > DemoService service = reference.get();
   > String message = service.sayHello("dubbo");
   > ```
   
   > Try this
   > 
   > ```
   > ReferenceConfig<DemoService> reference = new ReferenceConfig<>();
   > reference.setApplication(new ApplicationConfig("dubbo-demo-api-consumer"));
   > reference.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181"));
   > reference.setInterface(DemoService.class);
   > DemoService service = reference.get();
   > String message = service.sayHello("dubbo");
   > ```
   
   1.  我跑单测时会启动spring容器注册dubbo service ,然后在单测里会用@DubboReference注入service去执行一些方法测试
   
   
   问题: 
   @DubboReference注入的service时不会确保该service一定成功被注册到注册中心之后再被引用,所以抛了service找不到的错误
   
   
   我个人觉得,如果按照spring的逻辑,@Autowried注入一个bean应该是可以确保这个bean生命周期做完成再可用,而@DubboReference似乎没做这些处理。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org