(1)创建Maven工程(WAR)dubboxdemo-service  ,在pom.xml中引入依赖

<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>cn.itcast.dubboxdemo</groupId>

<artifactId>dubboxdemo-service</artifactId>

<version>0.0.1-SNAPSHOT</version>

<packaging>war</packaging>

<properties>

<spring.version>4.2.4.RELEASE</spring.version>

</properties>

<dependencies>

<!-- Spring -->

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-context</artifactId>

<version>${spring.version}</version>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-beans</artifactId>

<version>${spring.version}</version>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-webmvc</artifactId>

<version>${spring.version}</version>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-jdbc</artifactId>

<version>${spring.version}</version>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-aspects</artifactId>

<version>${spring.version}</version>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-jms</artifactId>

<version>${spring.version}</version>

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-context-support</artifactId>

<version>${spring.version}</version>

</dependency>

<!-- dubbo相关 -->

<dependency>

<groupId>com.alibaba</groupId>

<artifactId>dubbo</artifactId>

<version>2.8.4</version>

</dependency>

<dependency>

<groupId>org.apache.zookeeper</groupId>

<artifactId>zookeeper</artifactId>

<version>3.4.6</version>

</dependency>

<dependency>

<groupId>com.github.sgroschupf</groupId>

<artifactId>zkclient</artifactId>

<version>0.1</version>

</dependency>

<dependency>

<groupId>javassist</groupId>

<artifactId>javassist</artifactId>

<version>3.11.0.GA</version>

</dependency>

</dependencies>

<build>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<version>2.3.2</version>

<configuration>

<source>1.7</source>

<target>1.7</target>

</configuration>

</plugin>

<plugin>

<groupId>org.apache.tomcat.maven</groupId>

<artifactId>tomcat7-maven-plugin</artifactId>

<configuration>

<!-- 指定端口 -->

<port>8081</port>

<!-- 请求路径 -->

<path>/</path>

</configuration>

</plugin>

</plugins>

</build>

</project>

(2)在工程的webapps下创建WEB-INF文件夹,创建web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns="http://java.sun.com/xml/ns/javaee"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

version="2.5">

<!-- 加载spring容器 -->

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:applicationContext*.xml</param-value>

</context-param>

<listener>       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

</web-app>

(3)创建业务接口

创建包cn.itcast.dubbodemo.service,用于存放业务接口,创建接口

package cn.itcast.dubbodemo.service;

/**

* 业务接口

* @author Administrator

*

*/

public interface UserService {

public String getName();

}

(4)创建业务实现类

创建包cn.itcast.dubbodemo.service.impl ,用于存放业务实现类。创建业务实现类:

package cn.itcast.dubbodemo.service.impl;

import com.alibaba.dubbo.config.annotation.Service;

import cn.itcast.dubbodemo.service.UserService;

@Service

public class UserServiceImpl implements UserService {

public String getName() {

return "itcast";

}

}

注意:Service注解与原来不同,需要引入com.alibaba包下的

(5)编写配置文件

在src/main/resources下创建applicationContext-service.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:p="http://www.springframework.org/schema/p"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:mvc="http://www.springframework.org/schema/mvc"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.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.xsd">

<dubbo:application name="dubboxdemo-service"/>

<dubbo:registry address="zookeeper://192.168.25.132:2181"/>

<dubbo:annotation package="cn.itcast.dubboxdemo.service" />

</beans>

注意:dubbo:annotation用于扫描@Service注解。

(6)测试运行

tomcat7:run

Dubbox服务的提供方开发的更多相关文章

  1. Dubbox服务的提供方配置

    在src/main/resources下创建applicationContext-service.xml ,内容如下: <?xml version="1.0" encodin ...

  2. Dubbox服务的消费方开发

    开发步骤: (1)创建Maven工程(WAR)dubboxdemo-web ,在pom.xml引入依赖 ,同“dubboxdemo-service”工程.区别就是把tomcat插件的运行端口改为808 ...

  3. Re:从 0 开始的微服务架构--(三)微服务架构 API 的开发与治理--转

    原文来自:聊聊架构公众号 前面的文章中有说到微服务的通信方式,Martin Folwer 先生在他对微服务的定义中也提到“每个服务运行在其独立的进程中,服务与服务间采用 轻量级的通信机制 互相协作(通 ...

  4. Dubbo学习笔记9:Dubbo服务提供方启动流程源码分析

    首先我们通过一个时序图,直观看下Dubbo服务提供方启动的流程: 在<Dubbo整体框架分析>一文中我们提到,服务提供方需要使用ServiceConfig API发布服务,具体是调用代码( ...

  5. 基于spring-cloud的微服务(2) eureka服务提供方的注册和消费方的消费

    启动Eureka注册中心之后,服务提供方就可以注册到Eureka上去(作为一个Eureka的客户端) 我们使用IDEA提供的spring initializer来新建一个springcloud项目 填 ...

  6. [dubbo 源码之 ]1. 服务提供方如何发布服务

    服务发布 启动流程 1.ServiceConfig#export 服务提供方在启动部署时,dubbo会调用ServiceConfig#export来激活服务发布流程,如下所示: Java API: ` ...

  7. SpringBoot微服务电商项目开发实战 --- Kafka集成接入

    kafka作为消息中间件的一款产品,她比较轻量级,在吞吐量方面很优秀,默认消息持久化到硬盘当中 168小时=7天,log.retention.hours=168,比较适合来做运营的统计.其他的不多讲, ...

  8. 基于.net的微服务架构下的开发测试环境运维实践

    眼下,做互联网应用,最火的架构是微服务,最热的研发管理就是DevOps, 没有之一.微服务.DevOps已经被大量应用,它们已经像传说中的那样,可以无所不能.特来电云平台,通过近两年多的实践,发现完全 ...

  9. python的flex服务端数据接口开发

    python的flex服务端数据接口开发 python 如果给flex提供服务端,需要提供一个网关和一个可供客户端(flex)调用的类.这方面我更加推荐用twisted来写这个网关,因为twisted ...

随机推荐

  1. Linux运维常用脚本整理

    .查找当前目录下占用为0字节的文件并删除 find ./ -type f -size -exec rm -rf {}\;    #此命令不要用于对根目录0字节文件的操作 .将系统进程按内存占用大小排列 ...

  2. DecimalFormat数字格式化

    DecimalFormat可以按照需要格式化数字,下面简单介绍一下几种使用.其中自己也踏踏实实踩了坑,谨此记录. 保留位数设置 public class DecimalUtils { //保留2位,不 ...

  3. 使用 sar 查看网卡的流量

    1.常用命令 sar -n DEV #查看当天从零点到当前时间的网卡流量信息 sar -n DEV 1 10 #每秒显示一次,共显示10次 sar -n DEV -f /var/log/sa/saxx ...

  4. 【leetcode】654. Maximum Binary Tree

    题目如下: Given an integer array with no duplicates. A maximum tree building on this array is defined as ...

  5. SQL Server 2014 安装说明

    SQL Server 2014 安装说明 本节内容将说明如何通过安装向导在 Windows Server 2012 R2 上安装 SQL Server 2014. 先从 MSDN 网站上下载安装了 S ...

  6. 【持久层】Druid简介

    Druid首先是一个数据库连接池.Druid是目前最好的数据库连接池,在功能.性能.扩展性方面,都超过其他数据库连接池,包括DBCP.C3P0.BoneCP.Proxool.JBoss DataSou ...

  7. 【Linux】 Centos7 安装 mysql-8.0

    本文介绍使用rpm包安装mysql, 以 mysql-8.0.17-1.el7.x86_64.rpm-bundle.tar 为例: 1.下载 MySQL下载地址:https://dev.mysql.c ...

  8. Mistakes Collection I

    Symbol =>'s meaning: what it used to be like => what it should be. 1) mistake array subscript: ...

  9. 【c#技术】一篇文章搞掂:常见C#技术问题

    1.事件作为参数传递 public class Para { // 定义一种委托(事件类型),可以在此定义这个事件的返回值和参数 public delegate object GetDataMetho ...

  10. tomcat 高并发

    转自 http://blog.csdn.net/feng27156/article/details/19420695 一.容器简化了程序员自身的多线程编程. 各种Web容器,如Tomcat,Resio ...