dubbo icon indicating copy to clipboard operation
dubbo copied to clipboard

建议注解可以和XML配置一样,直接注入一个springbean,方便业务服务无改动使用

Open futcity opened this issue 7 years ago • 3 comments

Environment

  • Dubbo version: 2.6.X 2.7.X
  • Operating System version: mac
  • Java version: 1.8

情景

我们正常使用

@Service
public class DemoService {

    @Reference(version = "1.2.3")
    private XXService xxService;

}

期望使用

@Configuration
public class DubboConfig {

     @ReferenceConsumer(version = "1.2.3")
     private XXService xxService;

}

@Service
public class BXXServiceImpl {
    
    @Autowired
    private XXService xxService; 

}

@Service
public class AXXServiceImpl {
    
    @Autowired
    private XXService xxService; 

}

希望能够用spring的方式去注入对象,目前dubbo通过XML配置是注册到spring的bean,但是@Reference并不是。 想法是加一个PostProcessor去做一次registry一个BeanDefinition

futcity avatar Dec 27 '18 11:12 futcity

I know that there are some RPC frameworks have the configuration as this issue shown. Maybe we should take this style of configuration into consideration.

lexburner avatar Dec 28 '18 12:12 lexburner

这个命名我个人觉得,Reference已经具有Consumer的意思,所以我建议@ReferenceBean是不是更好?

当前呢,可以通过以下方式来实现,可能会稍微麻烦一些

@Configuration
public class DubboConfig {

    @Reference(version = "${demo.service.version}")
    private DemoServie demoService;

    @Bean
    public DemoServie demoServie() {
        return demoService;
    }   
}

chenlushun avatar Dec 28 '18 13:12 chenlushun

只是使用方式问题,自己可以封装一个Bean, 里面持有reference字段就好了

zonghaishang avatar Dec 30 '18 06:12 zonghaishang