(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. Shell基本概述

    目录 Shell01--基本概述 1. Shell课程大纲介绍 2. 什么是Shell ? 3. 什么是Shell脚本 ? 4. 为什么要学Shell编程 ? 5. 学习Shell编程需要哪些知识 ? ...

  2. js使用childnodes获取子节点时多了text节点

    当我们获取标签的节点时如果使用childnodes发现它会把空格和回车都算着节点,明明里面才有3个节点,结果显示5个,而且childnodes[0]="text" 在IE浏览器中没 ...

  3. java23种设计模式(二)-- 建造者模式和原型模式

    一.建造者模式 将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创造不同的表示. 特点: (1).在某些属性没有赋值之前,复杂对象不能作为一个完整的产品使用.比如汽车包括方向盘.车门.发动机 ...

  4. testNG 并发测试

     invocationCount是并发数,threadPoolSize是线程数,当线程是1的时候就是依次执行n次,当线程是并发次数时,就是同时执行n次    @Test public void abc ...

  5. java.sql.SQLException: Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_0900_ai_ci,IMPLICIT) for operation '='

    查询视图时报错:java.sql.SQLException: Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_ ...

  6. SQL BETWEEN运算符

    SQL BETWEEN运算符 BETWEEN 操作符用于选取介于两个值之间的数据范围内的值. SQL BETWEEN 运算符 BETWEEN运算符选择给定范围内的值.值可以是数字,文本或日期. BET ...

  7. Python基础教程(003)--Python的设计目标

    前言 了解Python的设计目标,这节是了解Python的背景,不需要掌握,但是需要你知道有这个东西.就是Python的目的是什么.作者开发这个Python语言的目的是什么. 知识点 一门简单直观的语 ...

  8. Python每日一题 005

    任一个英文的纯文本文件,统计其中的单词出现的个数. 代码 # coding:utf-8 import re def get_word(filename): fp=open(filename," ...

  9. BZOJ 3653: 谈笑风生(主席树)

    传送门 解题思路 首先对于一个\(a\)来说,要求\(b\)和\(c\),那么\(a,b,c\)一定在一条链上.把\(b\)分类讨论,如果\(b\)是\(a\)的祖宗,这个方案数就很好统计了,就是\( ...

  10. lnmp 一键安装详解

    1.使用putty或类似的SSH工具登陆VPS或服务器: 登陆后运行:screen -S lnmp 如果提示screen: command not found 命令不存在可以执行:yum instal ...