Maven--SpringBoost--Dubbo
整个项目是多系统的,使用Maven--SpringBoot--Dubbo:
我做的项目下的路径关系:
在oms_parent父pom文件:(dubbo和zookeeper整合springboot)只需注入下面两个依赖
<dependency>
<groupId>com.alibaba.spring.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency>
这里将提供接口,进行业务操作的系统称作提供者,调用接口的称作消费者,这关系是相对的,一个系统既可以对外提供相应接口,也可以调用其他系统的接口。
在springBoot项目中,添加上述依赖后,在application.yml文件中配置下面内容。
提供者:application.yml
dubbo:
application:
id: oms_sso_service
name: oms_sso_service
registry:
address: zookeeper://127.0.0.1:2181
protocol:
id: dubbo
name: dubbo
port: 20880
status: server
例如:oms_parent 下的子工程,oms_sso_interface和oms_sso_service
oms_sso_interface仅仅只是一个接口jar,包含LoginService接口,他的实现类在oms_sso_service(业务系统, war)中,oms_sso_service的pom中依赖oms_sso_interface,实现接口内容,如下图,在实现类上实现注解,dubbo包下的service注解,暴露接口class文件
SpringBoot的@Component注解交给框架管理。
需要发布的@service添加注解
oms_sso_service启动类上的注解添加,@EnabelDubboConfiguration
以上配置完成,启动即可在zookeeper上注册服务。
消费者端:
消费者端工程,例如:oms_portal 同样需要在该pom中添加依赖接口
<parent>
<artifactId>oms_parent</artifactId>
<groupId>com.softcit.oms</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../oms_parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>oms_portal</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.softcit.oms</groupId>
<artifactId>wms_entity</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.softcit.oms</groupId>
<artifactId>oms_sso_interface</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
1、 启动类同样添加注解 @EnabelDubboConfiguration
2、 Application.yml文件
dubbo:
application:
id: oms_portal
name: oms_portal
registry:
address: zookeeper:// 127.0.0.1:2181
protocol:
id: dubbo
name: dubbo
port: 20880
3、 只需要在调用接口方法的类中注入,暴露的LoginService接口,使用dubbo注解
@Reference 如下:timeout设计消费端的连接超时时间
public class LoginController {
@Reference(timeout=10000)
private LoginServiceloginService;