SpringBoot 集成 Dubbo

1. 搭建zookeeper环境

#下载zookeeper
wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz
#解压至安装目录
tar -zvxf zookeeper-3.4.10.tar.gz
#修改zookeeper配置
cd zookeeper-3.4.10/conf
cp zoo_tmp.cfg zoo.cfg
#修改指向dataDir的地址
vim  zoo.cfg
#####
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
dataDir=/usr/local/zoodata
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
#####

#启动zookeeper
cd ../bin
./zkServer.sh start
#查看运行状态
./zkServer.sh stauts


2. 我是使用XML配置方式

2.1 创建提供者XML(information-provider.xml)

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans        
	http://www.springframework.org/schema/beans/spring-beans.xsd        
	http://code.alibabatech.com/schema/dubbo        
	http://code.alibabatech.com/schema/dubbo/dubbo.xsd 
	http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-4.0.xsd">
	
	
	<!-- 提供方应用信息,用于计算依赖关系 -->
	<dubbo:application name="information-provider" />

	<!-- 使用zookeeper注册中心暴露服务地址 -->
	<dubbo:registry address="${zookeeper.address}" check="false"  subscribe="false" register="" />

	
    <dubbo:annotation package="com.onem2.information.dubbo" />
    
    <!-- 用dubbo协议在20880端口暴露服务 -->
	<dubbo:protocol name="dubbo" port="${dubbo.port}" />
    
    <dubbo:provider timeout="200000"/>
</beans>

2.2 修改 Application.java

package com.onem2;

import javax.servlet.MultipartConfigElement;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.MultipartConfigFactory;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.ImportResource;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication
@ServletComponentScan
@EnableScheduling
@EnableTransactionManagement
@EnableAspectJAutoProxy
@EnableAutoConfiguration
@Configuration
@ImportResource(locations = { "classpath:dubbo/information-provider.xml" })
@MapperScan("com.onem2.information.*.mapper")
public class Application {

    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        factory.setMaxFileSize("10240KB");
        factory.setMaxRequestSize("10240KB");
        return factory.createMultipartConfig();
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

可通过管理工具查看是否注册完成:

https://download.csdn.net/download/u012547633/10434224

dubbo-admin可视化控制台,链接地址请修改WEB-INF/dubbo.properties,可监控链接的zookeeper服务,清空tomcat的ROOT,然后将文件解压在里面。



猜你喜欢

转载自blog.csdn.net/u012547633/article/details/80431002