博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用JavaConfig方式配置dubbox
阅读量:4589 次
发布时间:2019-06-09

本文共 1740 字,大约阅读时间需要 5 分钟。

为了迎合Spring的所有配置方式,增加了无XML配置实现,在此不对两种方式的优劣做比较,请根据项目的使用习惯做出合理选择。

1. 模块描述

实现Spring的JavaConfig配置方式,使用 Main.main(args) (需传参javaconfig设置使用JavaConfigContainer) 启动时可直接扫描 dubbo.spring.javaconfig包下的所有的Spring配置类

2. 使用示例

使用示例在dubbo-demo/dubbo-demo-consumer模块中,相关配置方式参考 

2.1 代码解释

  • dubbo-demo-consumer/../DubboDemoConsumerConfig 等同于 dubbo-demo-consumer/../dubbo-demo-consumer.xml
  • dubbo-demo-consumer/../DubboDemoActionConfig 等同于 dubbo-demo-consumer/../dubbo-demo-action.xml
  • dubbo-demo-consumer/../DemoJavaConfigAction 等同于 dubbo-demo-consumer/../DemoAction
  • dubbo-demo-consumer/../DemoJavaConfigConsumer 以JavaConfig方式启动示例程序

2.2 示例演示

  1. 运行dubbo-demo-provider/../DemoProvider
  2. 运行dubbo-demo-consumer/../DemoJavaConfigConsumer
  3. 查看console输出

3. 无XML配置

将XML配置方式转换为JavaConfig配置,demo中未涉及到的配置类,请参照  实现

@Configurationpublic class DubboDemoConsumerConfig {    public static final String APPLICATION_NAME = "consumer-of-helloworld-app";    public static final String REGISTRY_ADDRESS = "zookeeper://127.0.0.1:2181";    public static final String ANNOTATION_PACKAGE = "com.alibaba.dubbo.demo.consumer";    @Bean    public ApplicationConfig applicationConfig() {        ApplicationConfig applicationConfig = new ApplicationConfig();        applicationConfig.setName(APPLICATION_NAME);        return applicationConfig;    }    @Bean    public RegistryConfig registryConfig() {        RegistryConfig registryConfig = new RegistryConfig();        registryConfig.setAddress(REGISTRY_ADDRESS);        return registryConfig;    }    @Bean    public AnnotationBean annotationBean() {        AnnotationBean annotationBean = new AnnotationBean();        annotationBean.setPackage(ANNOTATION_PACKAGE);        return annotationBean;    }}

转载于:https://www.cnblogs.com/devotion/p/5199398.html

你可能感兴趣的文章
gui编程实践(3)--记事本界面 JMenuBar JMenu
查看>>
黑马程序员--抽象类与接口
查看>>
IaaS,PaaS,SaaS 的区别
查看>>
Python复习基础篇
查看>>
关于Cocos2d-x中背景音乐和音效的添加
查看>>
.Net持续集成 —— Jenkins+Git+WebDeploy
查看>>
01_Numpy基本使用
查看>>
checkbox和文字对齐
查看>>
JConsole远程连接配置 服务器监控工具
查看>>
了解HTTP协议栈(实践篇)
查看>>
loj10035. 「一本通 2.1 练习 1」Power Strings
查看>>
%s的用法
查看>>
调用底层不能直接访问的类和方法
查看>>
清理缓存的方法 #DF
查看>>
JAVA array,map 转 json 字符串
查看>>
2017-12-27练习
查看>>
NET设计规范(二) 命名规范
查看>>
VMware 9.0.1安装Mac OS X Mountain Lion 10.8.2
查看>>
SSL延迟
查看>>
android新手关于左右滑动的问题,布局把<android.support.v4.view.ViewPager/><ImageView/> 放在上面就不行了。...
查看>>