spring maven 搭建dubbo框架 服务端
2017-02-05 15:15
513 查看
1 创建一个3 maven项目
1 定义接口项目 service
2 服务的提供者 provider
3 服务消费者 consumer
service 项目中只定义接口 不做其他任何事情
2 我们在该项目中创建一个接口 ,随便写一个方法
3 我们到 provider 项目中 pom.xml中引入相关包
在引入dubbo包的时候注意 为了防止spring冲突 要将spring依赖移除掉
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.3</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency> 我们需要实现service项目中的接口 所以也要引入service依赖
4 写一个实现类 来实现接口中的hello方法
5 我们再创建一个源文件夹来存放配置文件 src/main/resource
6 在源文件夹下创建目录 META-INF META-INF下再创建spring (必须叫这个名字)
7 创建两个xml文件 分别配置spring和dubbo
applicationContext.xml
applicationContext-dubbo.xml
8 在applicationContext.xml中 扫描 实现类所在的包
<context:component-scan base-package="com.dubbo.provider"></context:component-scan>
想被扫描到 实现类中也必须加入@Service注解
9 在applicationContext-dubbo.xml 中配置
<!-- 提供方应用信息,用于计算依赖关系 -->
<dubbo:application name="wy_provider" />
<!-- 使用zookeeper注册中心暴露服务地址 端口是zookeeper 中配置的2181-->
<dubbo:registry address="zookeeper://192.168.80.141:2181"/>
<!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="20880" />
<!-- 具体的实现bean -->
<bean id="testImpl" class="com.dubbo.provider.TestImpl" />
<!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="com.dubbo.service.Itest" ref="testImpl" />
10 写一个带有main方法的类
public static void main(String[] args) {
// TODO Auto-generated method stub
Main.main(args);
}
11 成功
1 定义接口项目 service
2 服务的提供者 provider
3 服务消费者 consumer
service 项目中只定义接口 不做其他任何事情
2 我们在该项目中创建一个接口 ,随便写一个方法
3 我们到 provider 项目中 pom.xml中引入相关包
在引入dubbo包的时候注意 为了防止spring冲突 要将spring依赖移除掉
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.3</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency> 我们需要实现service项目中的接口 所以也要引入service依赖
4 写一个实现类 来实现接口中的hello方法
5 我们再创建一个源文件夹来存放配置文件 src/main/resource
6 在源文件夹下创建目录 META-INF META-INF下再创建spring (必须叫这个名字)
7 创建两个xml文件 分别配置spring和dubbo
applicationContext.xml
applicationContext-dubbo.xml
8 在applicationContext.xml中 扫描 实现类所在的包
<context:component-scan base-package="com.dubbo.provider"></context:component-scan>
想被扫描到 实现类中也必须加入@Service注解
9 在applicationContext-dubbo.xml 中配置
<!-- 提供方应用信息,用于计算依赖关系 -->
<dubbo:application name="wy_provider" />
<!-- 使用zookeeper注册中心暴露服务地址 端口是zookeeper 中配置的2181-->
<dubbo:registry address="zookeeper://192.168.80.141:2181"/>
<!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="20880" />
<!-- 具体的实现bean -->
<bean id="testImpl" class="com.dubbo.provider.TestImpl" />
<!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="com.dubbo.service.Itest" ref="testImpl" />
10 写一个带有main方法的类
public static void main(String[] args) {
// TODO Auto-generated method stub
Main.main(args);
}
11 成功
相关文章推荐
- spring maven 搭建dubbo框架 (准备工作)
- spring maven 搭建dubbo框架 消费端
- spring maven 搭建dubbo框架(dubbo-admin)
- Dubbo——基于Zookeeper服务框架搭建及案例演示
- 阿里dubbo框架使用系列:开发环境搭建之zookeeper注册中心(单节点)
- 从0开始搭建:分布式服务框架-Maven多模块+Dubbo+Zookeeper++SpringMVC+mybatis自动生成
- Spring + Dubbo + zookeeper (linux) 框架搭建
- 用“MEAN”技术栈开发web应用(二)express搭建服务端框架
- 淘宝SOA框架dubbo学习(2)--搭建Zookeeper注册中心服务
- 160719、Spring + Dubbo + zookeeper (linux) 框架搭建
- mina 框架java服务端的搭建和通信。
- 复习springMVC+hibernate+dubboProvider搭建框架
- 用.Net打造一个移动客户端(Android/IOS)的服务端框架NHM(三)——搭建Android开发环境,用Hibernate生成Android项目的Model层
- Maven多模块,Dubbo分布式服务框架,SpringMVC,前后端分离项目,基础搭建,搭建过程出现的问题
- dubbo框架搭建
- springMVC+spring+mybatis 开发http接口服务端(1. ssm框架搭建)
- Spring4.1.6 + Mybatis3.2.8 (+ Dubbo可选) 框架搭建
- 使用Apache MINA框架搭建服务端
- 淘宝SOA框架dubbo学习(1)--搭建Zookeeper注册中心
- 分布式服务框架 dubbo/dubbox 的搭建