springboot+dubbo+myBatis實現微服務集成

springboot+dubbo+myBatis實現微服務集成


  • 代碼下載:https://download.csdn.net/download/typ1805/10485048
  • 微服務架構成了當下的技術熱點,實現微服務是要付出很大成本的,但也許是由於微服務的優勢太過於吸引人,以致於大部分開發者都將它當成將來的發展趨勢。

微服務架構的演進過程

  • dubbo的用戶手冊中介紹了服務化架構的進化過程,以下圖:
    這裏寫圖片描述

微服務的技術關注點

  • 要實現一個微服務的架構,咱們須要關注的技術點包括:服務註冊、發現、負載均衡和健康檢查,前端路由(網關),容錯,服務框架的選擇,動態配置管理等模塊。這些模塊能夠組成一個簡化的微服務架構圖以下:
    這裏寫圖片描述

使用dubbo+zookeeper實現簡化的微服務架構

    第一步:zookeeper集羣的部署
使用zookeeper做爲dubbo的註冊中心,部署起來並不麻煩。爲了保持註冊中心的高可用性,在生產環境下咱們須要配置多個zookeeper協同運行。在集羣模式下,zookeeper會基於Paxos算法從集羣中選擇一臺做爲leader,其餘機器做爲follower,註冊中心的數據都以leader爲準。一臺zk機器成爲leader的條件是超過這臺機器是可用的,且被超過半數的機器選舉爲leader。基於這種實現方式,咱們選擇zk集羣的數量時最好爲奇數個,最少爲3個,這樣只要有超過半數的zk機器存活那註冊中心就是可用的。
注:若是咱們選擇2臺機器做爲zk的集羣,那隻要有一臺zk掛掉,另外一臺機器就沒法獲得超過半數的選票,那麼這個zk集羣就直接失效了。所以選2臺機器做爲zk集羣的穩定性在理論上不如一臺機器做爲註冊中心的穩定性。

以3臺機器做爲zk集羣爲例,每臺zk的具體部署方式爲:html

一、下載安裝包並解壓到安裝目錄,zookeeper安裝包的下載地址爲: http://www.apache.org/dist/zookeeper/
二、進入解壓目錄的conf文件夾,配置zookeeper啓動的基本參數。
在conf文件夾下有一個 zoo_sample.cfg的文件,是zk啓動的配置樣例,zookeeper進程在啓動的時候會找zoo.cfg文件做爲默認的配置文件,因此咱們複製一個名稱爲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=D:/zookeeper-3.4.12/data
dataLogDir=D:/zookeeper-3.4.12/logs
# 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集羣的部署
# server.A=B:C:D
#  A爲數字,標識這條配置爲第幾個zk服務器,即機器id
#  B爲host名,標識這個服務器的主機地址
#  C和D爲zk集羣的成員用於選舉leader時的通信端口
server.1=zoo1:2888:3888
server.2=zoo2:2888:3888
server.3=zoo3:2888:3888
View Code

運行zookeeper進程,在zookeeper目錄下的bin文件夾中,運行前端

./zkServer.sh start
        ps: 中止方法——運行 ./zkServer.sh stop
  • 第二步:開發前端服務和後端通用服務,maven模塊結構,如圖:
    這裏寫圖片描述

springboot-dubbo-parent的pom.xml文件:java

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>springboot-dubbo-parent</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <name>springboot-dubbo-parent</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <modules> <module>springboot-dubbo-server</module> <module>springboot-dubbo-client</module> </modules> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <!-- 在properties中統一控制依賴包的版本,更清晰--> <dubbo.version>2.5.3</dubbo.version> <zk.version>3.4.5</zk.version> <zkclient.version>0.1</zkclient.version> </properties> <dependencyManagement> <!--dependencyManagement用於管理依賴版本號--> <dependencies> <!--刪除spring-boot-starter和spring-boot-starter-test,--> <!--由於parent中繼承的祖先中已經有了,而且通常dependencyManagement管理的依賴都要寫版本號--> <!--<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency>--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>1.5.9.RELEASE</version> </dependency> <!--新增後續dubbo項目中所需依賴,dubbo、zk--> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>${dubbo.version}</version><!--使用properties中配置的版本號--> <exclusions> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>${zk.version}</version> <exclusions> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </exclusion> <exclusion> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.github.sgroschupf</groupId> <artifactId>zkclient</artifactId> <version>${zkclient.version}</version> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>

springboot-dubbo-server的pom.xml文件:mysql

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>springboot-dubbo-server</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <name>springboot-dubbo-server</name> <description>Demo project for Spring Boot</description> <parent> <groupId>com.example</groupId> <artifactId>springboot-dubbo-parent</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <modules> <module>springboot-dubbo-api</module> <module>springboot-dubbo-provider</module> </modules> </project> 

springboot-dubbo-provider的pom.xml文件:git

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example.demo.provider</groupId> <artifactId>apringboot-dubbo-provider</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>apringboot-dubbo-provider</name> <description>Demo project for Spring Boot</description> <parent> <groupId>com.example</groupId> <artifactId>springboot-dubbo-server</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <properties> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!--新增後續dubbo項目中所需依賴,dubbo、zk。 父模塊pom中使用dependencyManagement來管理依賴版本號,子模塊pom中不須要再寫版本號,exclusion也不須要--> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> </dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> </dependency> <dependency> <groupId>com.github.sgroschupf</groupId> <artifactId>zkclient</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.1</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>com.example.admo.api</groupId> <artifactId>springboot-dubbo-api</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> 

dubbo配置文件provider.xml:github

<?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" 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"> <!-- 提供方應用信息,用於計算依賴關係 --> <dubbo:application name="demo-provider" /> <!-- 使用zookeeper註冊中心暴露服務地址 --> <dubbo:registry protocol="zookeeper" address="localhost:2181" timeout="60000"/> <!-- 用dubbo協議在20880端口暴露服務 --> <dubbo:protocol name="dubbo" port="20880" /> <!-- 暴露dubbo服務的方式一--> <!-- 使用註解方式暴露接口,會自動掃描package下全部包中dubbo相關的註解,這樣就不用在xml中再針對每一個服務接口配置dubbo:service interface--> <!--<dubbo:annotation package="com.example.demo.api.service"/>--> <!--另一種是全局新修改的辦法(timeout時間能夠本身調整)--> <dubbo:provider delay="-1" timeout="12000" retries="0"/> <!-- 暴露dubbo服務的方式二 --> <!-- 使用xml配置方式申明暴露一個接口服務,在程序啓動的時候會自動註冊到zookeeper。 等同於在類上打@service註解,打了註解就必需要用annotation指定啓動掃描路徑,使用這種方式,就不須要指定annotation了--> <dubbo:service interface="com.example.demo.api.service.UserService" ref="userService"/> <!-- 具體的實現bean,id與上面的ref要一致--> <bean id="userService" class="com.example.demo.provider.api.impl.UserServiceImpl"/> </beans>

mysql數據庫配置文件application.properties:web

spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8 spring.datasource.username=root spring.datasource.password=root spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.max-active=10 spring.datasource.max-idle=5 spring.datasource.min-idle=0

服務層接口實現類 UserServiceImpl.java文件:算法

package com.example.demo.provider.api.impl; import com.alibaba.dubbo.config.annotation.Service; import com.example.demo.api.model.User; import com.example.demo.api.service.UserService; import com.example.demo.provider.dao.UserMapper; import org.springframework.beans.factory.annotation.Autowired; /** * 路徑:com.example.demo.api.impl * 類名: * 功能: * 備註:該Service註解是dubbo的註解,不是spring的。若使用xml配置方式暴露接口,則不須要該註解。 * 建立人: * 建立時間: * 修改人: * 修改備註: * 修改時間: */ @Service public class UserServiceImpl implements UserService { @Autowired private UserMapper userMapper; @Override public User findOneById(Integer id) { return userMapper.findOneById(id); } } 

dao層接口Usermapper.java文件:spring

package com.example.demo.provider.dao; import com.example.demo.api.model.User; /** * 路徑:com.example.demo.dao * 類名: * 功能:《用一句話描述一下》 * 備註: * 建立人: * 建立時間: * 修改人: * 修改備註: * 修改時間: */ public interface UserMapper { User findOneById(Integer id); } 

myBatis的XML文件:sql

<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <mapper namespace="com.example.demo.provider.dao.UserMapper" > <select id="findOneById" resultType="com.example.demo.api.model.User"> select id,user_name from user </select> </mapper>

啓動類ApringbootDubboProviderApplication.java文件:

package com.example.demo.provider; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.tomcat.jdbc.pool.DataSource; import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ImportResource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.transaction.PlatformTransactionManager; /** * 路徑:com.example.demo.provider * 類名: * 功能:《用一句話描述一下》 * 備註: * 建立人: * 建立時間: * 修改人: * 修改備註: * 修改時間: */ @SpringBootApplication @MapperScan("com.example.demo.provider.dao") @ImportResource("classpath:provider.xml") public class ApringbootDubboProviderApplication { @Bean @ConfigurationProperties(prefix="spring.datasource") public DataSource dataSource() { return new org.apache.tomcat.jdbc.pool.DataSource(); } @Bean public SqlSessionFactory sqlSessionFactoryBean() throws Exception { SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); sqlSessionFactoryBean.setDataSource(dataSource()); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:/mapper/*.xml")); return sqlSessionFactoryBean.getObject(); } @Bean public PlatformTransactionManager transactionManager() { return new DataSourceTransactionManager(dataSource()); } public static void main(String[] args) throws InterruptedException { SpringApplication.run(ApringbootDubboProviderApplication.class, args); //pom中沒有加spring-boot-starter-web依賴,啓動時沒有tomcat容器,會自動退出,因此加了一個sleep防止自動退出 Thread.sleep(Long.MAX_VALUE); } } 

springboot-dubbo-api的pom.xml文件:

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example.admo.api</groupId> <artifactId>springboot-dubbo-api</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>springboot-dubbo-api</name> <description>Demo project for Spring Boot</description> <parent> <groupId>com.example</groupId> <artifactId>springboot-dubbo-server</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> 

api服務接口UserService.java文件:

package com.example.demo.api.service; import com.example.demo.api.model.User; /** * 路徑:com.example.demo.api.service * 類名: * 功能: * 備註: * 建立人: * 建立時間: * 修改人: * 修改備註: * 修改時間: */ public interface UserService { User findOneById(Integer id); } 

實體類User.java文件:

package com.example.demo.api.model; import java.io.Serializable; /** * 路徑:com.example.demo.api.model * 類名: * 功能:《用一句話描述一下》 * 備註: * 建立人: * 建立時間: * 修改人: * 修改備註: * 修改時間: */ public class User implements Serializable { private Integer id; private String user_name; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getUser_name() { return user_name; } public void setUser_name(String user_name) { this.user_name = user_name; } }

springboot-dubbo-client的pom.xml文件:

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>springboot-dubbo-client</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>springboot-dubbo-client</name> <description>Demo project for Spring Boot</description> <parent> <groupId>com.example</groupId> <artifactId>springboot-dubbo-parent</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <properties> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!--新增後續dubbo項目中所需依賴,dubbo、zk。 父模塊pom中使用dependencyManagement來管理依賴版本號,子模塊pom中不須要再寫版本號,exclusion也不須要--> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> </dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> </dependency> <dependency> <groupId>com.github.sgroschupf</groupId> <artifactId>zkclient</artifactId> </dependency> <dependency> <groupId>com.example.admo.api</groupId> <artifactId>springboot-dubbo-api</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> 

dubbo配置文件consumer.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" 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"> <!--消費方應用名,用於計算依賴關係,不是匹配條件,不要與提供方同樣 --> <dubbo:application name="demo-consumer"/> <!--zookeeper註冊中心 --> <dubbo:registry protocol="zookeeper" address="localhost:2181" timeout="60000"/> <!--關閉服務消費方全部服務的啓動檢查。dubbo缺省會在啓動時檢查依賴的服務是否可用,不可用時會拋出異常,阻止Spring初始化完成。--> <dubbo:consumer check="false" /> <!-- 使用註解方式建立遠程服務代理--> <dubbo:annotation package="com.example.demo.controller"/> <!-- 使用xml配置方式建立遠程服務代理,id即爲provider.xml中暴露的服務的id--> <!-- 等同於dubbo:annotation 加上代碼裏的@Reference註解--> <!--<dubbo:reference id="userService" interface="com.example.demo.api.service.UserService"/>--> </beans>

UserController.java文件:

package com.example.demo.controller; import com.alibaba.dubbo.config.annotation.Reference; import com.example.demo.api.model.User; import com.example.demo.api.service.UserService; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; /** * 路徑:com.example.demo.controller * 類名: * 功能:《用一句話描述一下》 * 備註: * 建立人: * 建立時間: * 修改人: * 修改備註: * 修改時間: */ @RestController @RequestMapping("/user") public class UserController { /** * 注入服務提供方暴露的接口,經過@Reference註解,dubbo會在掃描的時候自動代理接口,而後經過rpc調用遠程服務。 * 若是用xml配置方式,須要將@Reference換成@Autowired。 */ @Reference UserService userService; @RequestMapping("/find") @ResponseBody public User findOneById(Integer id){ System.out.println("------Controller--------id------"+id); User user = userService.findOneById(id); if(user == null){ user = new User(); } return user; } }

啓動類 SpringbootDubboClientApplication.java文件:

package com.example.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ImportResource; /** * 路徑:com.example.demo * 類名: * 功能:《用一句話描述一下》 * 備註: * 建立人: * 建立時間: * 修改人: * 修改備註: * 修改時間: */ @SpringBootApplication @ImportResource("classpath:consumer.xml") public class SpringbootDubboClientApplication { public static void main(String[] args) throws Exception{ SpringApplication.run(SpringbootDubboClientApplication.class, args); } }

啓動成功,如圖:
這裏寫圖片描述
這裏寫圖片描述

瀏覽器訪問,如圖:
這裏寫圖片描述

注意(遠程調用失敗問題):

Caused by: com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method subscribe in the service com.alibab

a.dubbo.registry.RegistryService. Tried 3 times of the providers[172.168.1.167:2181] (1/1) from the registry

172.168.1.167:2181 on the consumer 169.254.249.102 using the dubbo version2.4.9. Last error is: Invoke remote

method timeout.

解決方法一:

這個是因爲dubbo接口中的的傳輸對象沒有被序列化而致使的,只須要要檢查dubbo接口中參數中的實體類實現序列化(implementsSerializable)就能夠解決這一個異常.

解決方法二:

解決這個問題這個只須要從新暴露服務,在Zk上註冊服務提供者信息便可。具體就是要排查服務提供者可能出現的問題,解決後部署並重啓服務提供者便可。

解決方法三:

1.基本就是dubbo provider沒有啓動會形成這種狀況。

2.api和service是同一個項目,並非倆項目。

經過啓動api,run on server是不能啓動service的,必須經過config/startConfig.java,debug as java application啓動。

3.啓動思路總結:

1.api經過run on server啓動

2.service經過startConfig.java啓動。debug as java application

要想了解更多的信息能夠經過官方文檔進行學習:

dubbo中文文檔:http://dubbo.io/
zookeeper文檔:http://zookeeper.apache.org/

相關文章
相關標籤/搜索