博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用Springboot集成dubbox进行微服务治理
阅读量:2394 次
发布时间:2019-05-10

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

一、spring boot

作为spring家族中新成员,一出来就受到大家的欢迎,其基于Spirng 4.0和Servelet 3,实现免xml的方式,并将常用的Spring模块整合分组,不但提高了代码可读性,而且大大降低了代码编写难度。

二、dubbo

同样dubbo作为SOA治理框架,不但包含了服务提供者和消费者,还提供了管理平台、监控平台等等。在阿里开源后,立即受到了广大开发者的追捧。可惜的是由于阿里dubbo团队的解散,已经很久没有更新代码了,当前最新版本是

三、dubbox

很庆幸,由当当网等团队在dubbo基础上升级了,将Spring2.X升级到3.X,并支持基于Kryo和FST的高效序列化实现,支持REST等。

不过问题来了,dubbox还是只支持Spring3,而Spring boot要求Spring 4,因此需要升级dubbox支持4.0版本。

四、dubbox升级版,支持了Spring4.0,github地址:

五、集成Spring boot和dubbox

   (1)、原来Spring集成dubbo的时候需要配置如下xml

  (2)、改成Spring boot后只需要一个java类即可,这里表示向注册中心zookeeper注册服务。

/** * Created by chentian610. */@Configuration@PropertySource("classpath:dubbo.properties")public class DubboConfig {    @Value("${dubbo.application.name}")    private String dubbo_application_name;    @Value("${dubbo.registry.address}")    private String dubbo_registry_address;    /**     * 由《dubbo:application》转换过来     **/    @Bean    public ApplicationConfig applicationConfig() {        ApplicationConfig applicationConfig = new ApplicationConfig();        applicationConfig.setLogger("slf4j");        applicationConfig.setName(dubbo_application_name);        return applicationConfig;    }    /**    * 与
相当.提供方扫描带有@com.alibaba.dubbo.init.annotation.Reference的注解类 * */ @Bean public static AnnotationBean annotationBean() { AnnotationBean annotationBean = new AnnotationBean(); annotationBean.setPackage("com.chentian610");//多个包可使用英文逗号隔开 return annotationBean; } /** * 与
相当 * */ @Bean public RegistryConfig registryConfig() { RegistryConfig registryConfig = new RegistryConfig(); registryConfig.setAddress(dubbo_registry_address); return registryConfig; }}
(3)、在pom.xml中添加Spring boot支持

org.springframework.boot
spring-boot-starter
org.springframework.boot
spring-boot-starter-logging
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
org.springframework.boot
spring-boot-starter-logging
test
org.springframework.boot
spring-boot-starter-log4j2
(4)、指定Spring boot启动类

@SpringBootApplicationpublic class Application {    public static void main(String[] args) {        SpringApplication.run(Application.class, args);		try {			System.in.read();		} catch (IOException e) {			e.printStackTrace();		}    }}
(5)、具体业务类中调用dubbo服务,只需要添加@Reference注解即可

@Reference	private GetuiService getuiService;

六、最后启动各自服务,贴上,欢迎大家交流chentian610

转载地址:http://kuwob.baihongyu.com/

你可能感兴趣的文章
Listener--域对象属性变化监听器([ServletRequest | HttpSession | ServletContext] AttributeListener)API详解
查看>>
Listener--HttpSessionBindingListenerAPI及使用(在线人数统计)详解
查看>>
Listener--HttpSessionActivationListener(钝化、活化)API、配置和使用详解
查看>>
Filter--过滤器Filter概述、API、配置与使用详解
查看>>
Web--使用Filter和Cookie实现自动登录
查看>>
Web--Filter使用装饰器模式解决全站中文乱码问题
查看>>
JS--JavaScript入门(script标签使用与外部JavaScript文件引入)
查看>>
JS--JavaScript语句(表达式语句、语句块、条件语句if、switch)详解
查看>>
Struts2--非表单标签
查看>>
MyBatis--工作原理
查看>>
MyBatis--基础环境搭建
查看>>
UML--构件图详解
查看>>
UML--部署图详解
查看>>
MyBatis--SqlSessionFactory概述及创建方式
查看>>
MyBatis--核心组件:SqlSessionFactoryBuilder、SqlSessionFactory、SqlSession和SQL Mapper
查看>>
MyBatis--单表增删改查
查看>>
MySQL--基础三(条件查询)
查看>>
Maven--依赖配置和依赖范围
查看>>
Maven--排除依赖、归类依赖和优化依赖
查看>>
Maven--插件的获取和配置
查看>>