学习dubbo源码-新版本注解

服务发布与引用

image.png | left | 747x508

@Reference实现和@Autowired相似,参考了AutowiredAnnotationBeanPostProcessor

数据绑定

image.png | left | 747x756

自定义案例

1
2
3
4
@Configuration
@EnableDubboConfigBinding(prefix = "dubbo.registry", type = RegistryConfig.class)
public class MyDataBind {
}
1
2
3
4
5
6
7
8
9
10
11
12
public class MyTest {
@Test
public void demo1() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
ConfigurableEnvironment environment = context.getEnvironment();
environment.getSystemProperties().putIfAbsent("dubbo.registry.address", "zookeeper://127.0.0.1:2181");
context.register(MyDataBind.class);
context.refresh();
RegistryConfig bean = context.getBean(RegistryConfig.class);
Assert.assertNotNull(bean);
}
}

会将dubbo.registry前缀的参数绑定到RegistryConfig对象,并注入容器