参考:http://blog.csdn.net/aixiaoyang168/article/details/51362675

dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,是阿里巴巴SOA服务化治理方案的核心框架,每天为2,000+个服务提供3,000,000,000+次访问量支持,并被广泛应用于阿里巴巴集团的各成员站点(其他的详细介绍可以查看dubbo的官网地址http://dubbo.io/,写的很详细!)。

该demo是基于maven搭建的,项目架构基于SpringMVC,这里忽略spring的基本配置,着重介绍下dubbo部分的配置,以及dubbo后台管理系统

一、软件环境 
1、zookeeper 
下载地址:https://zookeeper.apache.org/releases.html 下载最新版的zookeeper,我这里使用的版本是 zookeeper-3.4.5.tar.gz 
2、springMVC (maven方式引入) 
3、dubbo (maven方式引入)

二、项目搭建 
这里我搭建了三个项目,分别为dubbo-api,dubbo-consumer,dubbo-provider

dubbo-api:主要是接口定义,供dubbo-consumer调用,以及dubbo-provider的service层去实现该接口,分离这一层的好处就是前端项目调用接口时候,直接调用dubbo-api的接口即可,不需要关注后端如何实现;而service层来具体实现该接口,进行业务逻辑处理,不需要关注dubbo-consumer 的controller层如何调用。

dubbo-consumer:主要controller层控制跳转等。

dubbo-provider:主要是service实现,结合数据层实现后端业务逻辑处理。

项目搭建完成之后,的结构图如下:

三、项目配置 
1、dubbo-api

Maven配置:

<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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>com.dubbo</groupId>

<artifactId>dubbo-api</artifactId>

<packaging>jar</packaging>

<version>1.0-SNAPSHOT</version>

<name>dubbo-api</name>

<url>http://maven.apache.org</url>

<build>

<plugins>

<plugin>

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

<version>2.0.2</version>

<configuration>

<source>1.5</source>

<target>1.5</target>

<fork>true</fork>

<meminitial>128m</meminitial>

<maxmem>512m</maxmem>

<encoding>UTF-8</encoding>

</configuration>

</plugin>

<plugin>

<artifactId>maven-eclipse-plugin</artifactId>

<version>2.5.1</version>

<configuration>

<additionalProjectnatures>

<projectnature>

org.springframework.ide.eclipse.core.springnature

</projectnature>

</additionalProjectnatures>

<additionalBuildcommands>

<buildcommand>

org.springframework.ide.eclipse.core.springbuilder

</buildcommand>

</additionalBuildcommands>

<downloadSources>false</downloadSources>

<downloadJavadocs>false</downloadJavadocs>

<wtpversion>1.5</wtpversion>

</configuration>

</plugin>

<!-- 要加上下面的一句,否则执行:mvn package -Dmaven.test.skip=true的时候会报错 -->

<plugin>

<artifactId>maven-war-plugin</artifactId>

<version>2.1.1</version>

</plugin>

</plugins>

</build>

<properties>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<spring.version>4.0.3.RELEASE</spring.version>

<org.codehaus.jackson>1.9.13</org.codehaus.jackson>

</properties>

<dependencies>

<!-- Test -->

<dependency>

<groupId>junit</groupId>

<artifactId>junit</artifactId>

<version>4.7</version>

<scope>test</scope>

</dependency>

</dependencies>

</project>

新建TestService接口类

package com.dubbo.service;

/**

* dubbo学习地址:http://blog.csdn.net/aixiaoyang168/article/details/51362675

*/

public interface TestService {

/**

* 测试发消息

* @param name

* @return

*/

public String sayHello(String name);

}

注意:这个项目最终打包成jar文件,直接maven引入到另外两个项目中

2、dubbo-consumer

Maven依赖:

<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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>com.dubbo</groupId>

<artifactId>dubbo-consumer</artifactId>

<packaging>war</packaging>

<version>1.0-SNAPSHOT</version>

<name>dubbo-consumer</name>

<url>http://maven.apache.org</url>

<build>

<finalName>dubbo-consumer</finalName>

<plugins>

<plugin>

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

<version>2.0.2</version>

<configuration>

<source>1.5</source>

<target>1.5</target>

<fork>true</fork>

<meminitial>128m</meminitial>

<maxmem>512m</maxmem>

<encoding>UTF-8</encoding>

</configuration>

</plugin>

<plugin>

<artifactId>maven-eclipse-plugin</artifactId>

<version>2.5.1</version>

<configuration>

<additionalProjectnatures>

<projectnature>

org.springframework.ide.eclipse.core.springnature

</projectnature>

</additionalProjectnatures>

<additionalBuildcommands>

<buildcommand>

org.springframework.ide.eclipse.core.springbuilder

</buildcommand>

</additionalBuildcommands>

<downloadSources>false</downloadSources>

<downloadJavadocs>false</downloadJavadocs>

<wtpversion>1.5</wtpversion>

</configuration>

</plugin>

<!-- 要加上下面的一句,否则执行:mvn package -Dmaven.test.skip=true的时候会报错 -->

<plugin>

<artifactId>maven-war-plugin</artifactId>

<version>2.1.1</version>

</plugin>

</plugins>

</build>

<properties>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<spring.version>4.0.3.RELEASE</spring.version>

<org.codehaus.jackson>1.9.13</org.codehaus.jackson>

</properties>

<dependencies>

<!-- Spring -->

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-core</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-orm</artifactId>

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

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-tx</artifactId>

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

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-test</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-webmvc</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</artifactId>

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

</dependency>

<dependency>

<groupId>org.springframework</groupId>

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

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

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-oxm</artifactId>

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

</dependency>

<dependency>

<groupId>org.slf4j</groupId>

<artifactId>slf4j-api</artifactId>

<version>1.7.2</version>

</dependency>

<dependency>

<groupId>log4j</groupId>

<artifactId>log4j</artifactId>

<version>1.2.17</version>

</dependency>

<dependency>

<groupId>org.slf4j</groupId>

<artifactId>slf4j-log4j12</artifactId>

<version>1.7.2</version>

</dependency>

<dependency>

<groupId>com.thoughtworks.xstream</groupId>

<artifactId>xstream</artifactId>

<version>1.2.2</version>

</dependency>

<dependency>

<groupId>ant</groupId>

<artifactId>ant</artifactId>

<version>1.7.0</version>

</dependency>

<!-- Test -->

<dependency>

<groupId>junit</groupId>

<artifactId>junit</artifactId>

<version>4.7</version>

<scope>test</scope>

</dependency>

<dependency>

<groupId>aopalliance</groupId>

<artifactId>aopalliance</artifactId>

<version>1.0</version>

</dependency>

<dependency>

<groupId>commons-dbcp</groupId>

<artifactId>commons-dbcp</artifactId>

<version>1.3</version>

</dependency>

<dependency>

<groupId>commons-fileupload</groupId>

<artifactId>commons-fileupload</artifactId>

<version>1.3</version>

</dependency>

<!--

<dependency>

<groupId>commons-logging</groupId>

<artifactId>commons-logging</artifactId>

<version>1.1.3</version>

</dependency>

-->

<dependency>

<groupId>commons-pool</groupId>

<artifactId>commons-pool</artifactId>

<version>1.5.4</version>

</dependency>

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>jstl</artifactId>

<version>1.1.2</version>

</dependency>

<!--

<dependency>

<groupId>com.oracle</groupId>

<artifactId>ojdbc14</artifactId>

<version>10.2.0.3.0</version>

</dependency>

-->

<dependency>

<groupId>taglibs</groupId>

<artifactId>standard</artifactId>

<version>1.1.2</version>

</dependency>

<dependency>

<groupId>commons-codec</groupId>

<artifactId>commons-codec</artifactId>

<version>1.5</version>

</dependency>

<dependency>

<groupId>commons-lang</groupId>

<artifactId>commons-lang</artifactId>

<version>2.1</version>

</dependency>

<dependency>

<groupId>net.sf.ezmorph</groupId>

<artifactId>ezmorph</artifactId>

<version>1.0.6</version>

</dependency>

<dependency>

<groupId>net.sf.json-lib</groupId>

<artifactId>json-lib</artifactId>

<version>2.3</version>

<classifier>jdk15</classifier>

</dependency>

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>servlet-api</artifactId>

<version>2.5</version>

<scope>provided</scope>

</dependency>

<dependency>

<groupId>org.json</groupId>

<artifactId>org.json</artifactId>

<version>chargebee-1.0</version>

</dependency>

<!-- json -->

<dependency>

<groupId>net.sf.json-lib</groupId>

<artifactId>json-lib</artifactId>

<version>2.4</version>

<classifier>jdk15</classifier>

</dependency>

<dependency>

<groupId>org.codehaus.jackson</groupId>

<artifactId>jackson-core-lgpl</artifactId>

<version>${org.codehaus.jackson}</version>

</dependency>

<dependency>

<groupId>org.codehaus.jackson</groupId>

<artifactId>jackson-mapper-lgpl</artifactId>

<version>${org.codehaus.jackson}</version>

</dependency>

<dependency>

<groupId>org.json</groupId>

<artifactId>json</artifactId>

<version>20140107</version>

</dependency>

<dependency>

<groupId>jaxen</groupId>

<artifactId>jaxen</artifactId>

<version>1.1.6</version>

</dependency>

<dependency>

<groupId>org.aspectj</groupId>

<artifactId>aspectjrt</artifactId>

<version>1.8.9</version>

</dependency>

<dependency>

<groupId>org.aspectj</groupId>

<artifactId>aspectjweaver</artifactId>

<version>1.8.9</version>

</dependency>

<!-- <dependency>

<groupId>commons-codec</groupId>

<artifactId>commons-codec</artifactId>

<version>1.9</version>

</dependency>

-->

<dependency>

<groupId>commons-logging</groupId>

<artifactId>commons-logging</artifactId>

<version>1.2</version>

</dependency>

<dependency>

<groupId>mysql</groupId>

<artifactId>mysql-connector-java</artifactId>

<version>5.1.38</version>

</dependency>

<!-- 阿里巴巴的druid数据源配置 -->

<dependency>

<groupId>com.alibaba</groupId>

<artifactId>druid</artifactId>

<version>1.0.18</version>

</dependency>

<!-- 文档处理所需的jar的依赖 -->

<dependency>

<groupId>commons-io</groupId>

<artifactId>commons-io</artifactId>

<version>2.4</version>

</dependency>

<dependency>

<groupId>org.apache.httpcomponents</groupId>

<artifactId>fluent-hc</artifactId>

<version>4.5.2</version>

</dependency>

<dependency>

<groupId>org.apache.httpcomponents</groupId>

<artifactId>httpclient</artifactId>

<version>4.5.2</version>

</dependency>

<dependency>

<groupId>org.apache.httpcomponents</groupId>

<artifactId>httpclient-cache</artifactId>

<version>4.5.2</version>

</dependency>

<dependency>

<groupId>org.apache.httpcomponents</groupId>

<artifactId>httpcore</artifactId>

<version>4.4.4</version>

</dependency>

<dependency>

<groupId>org.apache.httpcomponents</groupId>

<artifactId>httpclient-win</artifactId>

<version>4.5.2</version>

</dependency>

<dependency>

<groupId>org.apache.httpcomponents</groupId>

<artifactId>httpmime</artifactId>

<version>4.5.2</version>

</dependency>

<!-- dubbo -->

<dependency>

<groupId>com.alibaba</groupId>

<artifactId>dubbo</artifactId>

<version>2.5.3</version>

<exclusions>

<exclusion>

<artifactId>spring</artifactId>

<groupId>org.springframework</groupId>

</exclusion>

</exclusions>

</dependency>

<dependency>

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

<artifactId>zookeeper</artifactId>

<version>3.4.6</version>

<exclusions>

<exclusion>

<groupId>log4j</groupId>

<artifactId>log4j</artifactId>

</exclusion>

</exclusions>

</dependency>

<dependency>

<groupId>dom4j</groupId>

<artifactId>dom4j</artifactId>

<version>1.6.1</version>

</dependency>

<dependency>

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

<artifactId>zkclient</artifactId>

<version>0.1</version>

</dependency>

<dependency>

<groupId>com.dubbo</groupId>

<artifactId>dubbo-api</artifactId>

<version>1.0-SNAPSHOT</version>

</dependency>

</dependencies>

</project>

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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

<display-name>spring_Modle</display-name>

<session-config>

<session-timeout>30</session-timeout>

</session-config>

<context-param>

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

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

</context-param>

<context-param>

<param-name>log4jConfigLocation</param-name>

<param-value>classpath:log4j.properties</param-value>

</context-param>

<filter>

<filter-name>characterEncodingFilter</filter-name>

<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

<init-param>

<param-name>encoding</param-name>

<param-value>UTF-8</param-value>

</init-param>

<init-param>

<param-name>forceEncoding</param-name>

<param-value>true</param-value>

</init-param>

</filter>

<filter-mapping>

<filter-name>characterEncodingFilter</filter-name>

<url-pattern>*.action</url-pattern>

</filter-mapping>

<filter-mapping>

<filter-name>characterEncodingFilter</filter-name>

<url-pattern>*.jsp</url-pattern>

</filter-mapping>

<listener>

<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>

</listener>

<listener>

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

</listener>

<servlet>

<servlet-name>spring</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>

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

<param-value>classpath:context-dispatcher.xml</param-value>

</init-param>

</servlet>

<servlet-mapping>

<servlet-name>spring</servlet-name>

<url-pattern>*.action</url-pattern>

</servlet-mapping>

<welcome-file-list>

<welcome-file>index.jsp</welcome-file>

</welcome-file-list>

</web-app>

applicationContext.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:tx="http://www.springframework.org/schema/tx"

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

xsi:schemaLocation=

    http://www.springframework.org/schema/beans

    http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 

    http://www.springframework.org/schema/tx  

    http://www.springframework.org/schema/tx/spring-tx-4.0.xsd

    http://www.springframework.org/schema/mvc

    http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd

    http://www.springframework.org/schema/cache

    http://www.springframework.org/schema/cache/spring-cache-4.0.xsd

    http://www.springframework.org/schema/task

    http://www.springframework.org/schema/task/spring-task-4.0.xsd

    http://www.springframework.org/schema/context  

    http://www.springframework.org/schema/context/spring-context-4.0.xsd

    http://www.springframework.org/schema/aop

    http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">

<!-- 打开注解 -->

<context:annotation-config/>

<!-- 打开自动扫描 -->

<context:component-scan base-package="com.dubbo"/>

<!-- 定时器驱动 -->

<task:annotation-driven/>

<import resource="dubbo-config.xml"/>

</beans>

dubbo-config.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="test_consumer" />

<!-- 使用zookeeper注册中心暴露服务地址 -->

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

<!-- 声明需要暴露的服务接口 -->

<dubbo:reference interface="com.dubbo.service.TestService" id="testService" check="false" />

</beans>

context-dispatcher.xml

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

<beans default-lazy-init="true"

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

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

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

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

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

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

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

xsi:schemaLocation=

       http://www.springframework.org/schema/beans  

       http://www.springframework.org/schema/beans/spring-beans-3.1.xsd

       http://www.springframework.org/schema/mvc  

       http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd  

       http://www.springframework.org/schema/context 

       http://www.springframework.org/schema/context/spring-context-4.0.xsd

       http://www.springframework.org/schema/aop

      http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">

<!-- 使用注解的包,包括子集 --><!-- http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd -->

<context:component-scan base-package="com.dubbo" />

<aop:aspectj-autoproxy/>

<!-- 通过注解,把URL映射到Controller上,该标签默认注册DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter-->

<mvc:annotation-driven>

<mvc:message-converters>

<bean class="org.springframework.http.converter.StringHttpMessageConverter">

<!--  <constructor-arg value="UTF-8" />-->

<property name="supportedMediaTypes">

<list>

<value>text/html;charset=UTF-8</value>

</list>

</property>

</bean>

</mvc:message-converters>

</mvc:annotation-driven>

<!-- 视图解析器 -->

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />

<property name="prefix" value="/WEB-INF/pages/" />

<property name="suffix" value=".jsp"></property>

</bean>

<bean id="defaultJsonView" class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"/>

<bean id="multipartResolver"

class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />

</beans>

新建MyController类

package com.dubbo.controller;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.bind.annotation.ResponseBody;

import com.dubbo.service.TestService;

@Controller

public class MyController {

@Autowired

private TestService testService;

/**

* \brief 方法名与方法功能概述

* @param name

* @return

* @attention 访问方式:http://127.0.0.1:8080/dubbo-controller/test.action?name=toto

* @author toto

* @date 2017年5月24日

* @note  begin modify by 修改人 修改时间   修改内容摘要说明

*/

@RequestMapping(value = "/test")

@ResponseBody

public String testSay(@RequestParam(value = "name",defaultValue = "") String name) {

StringBuffer sb = new StringBuffer();

sb.append("Dubbo:").append(testService.sayHello(name));

return sb.toString();

}

}

dubbo-consumer终打包成dubbo-consumer.war放在tomcat或其他容器中运行。

3、dubbo-provider

Maven配置:

<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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>com.dubbo</groupId>

<artifactId>dubbo-provider</artifactId>

<packaging>war</packaging>

<version>1.0-SNAPSHOT</version>

<name>dubbo-provider</name>

<url>http://maven.apache.org</url>

<build>

<finalName>dubbo-provider</finalName>

<plugins>

<plugin>

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

<version>2.0.2</version>

<configuration>

<source>1.5</source>

<target>1.5</target>

<fork>true</fork>

<meminitial>128m</meminitial>

<maxmem>512m</maxmem>

<encoding>UTF-8</encoding>

</configuration>

</plugin>

<plugin>

<artifactId>maven-eclipse-plugin</artifactId>

<version>2.5.1</version>

<configuration>

<additionalProjectnatures>

<projectnature>

org.springframework.ide.eclipse.core.springnature

</projectnature>

</additionalProjectnatures>

<additionalBuildcommands>

<buildcommand>

org.springframework.ide.eclipse.core.springbuilder

</buildcommand>

</additionalBuildcommands>

<downloadSources>false</downloadSources>

<downloadJavadocs>false</downloadJavadocs>

<wtpversion>1.5</wtpversion>

</configuration>

</plugin>

<!-- 要加上下面的一句,否则执行:mvn package -Dmaven.test.skip=true的时候会报错 -->

<plugin>

<artifactId>maven-war-plugin</artifactId>

<version>2.1.1</version>

</plugin>

</plugins>

</build>

<properties>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<spring.version>4.0.3.RELEASE</spring.version>

<org.codehaus.jackson>1.9.13</org.codehaus.jackson>

</properties>

<dependencies>

<!-- Spring -->

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-core</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-orm</artifactId>

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

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-tx</artifactId>

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

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-test</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-webmvc</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</artifactId>

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

</dependency>

<dependency>

<groupId>org.springframework</groupId>

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

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

</dependency>

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-oxm</artifactId>

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

</dependency>

<dependency>

<groupId>org.slf4j</groupId>

<artifactId>slf4j-api</artifactId>

<version>1.7.2</version>

</dependency>

<dependency>

<groupId>log4j</groupId>

<artifactId>log4j</artifactId>

<version>1.2.17</version>

</dependency>

<dependency>

<groupId>org.slf4j</groupId>

<artifactId>slf4j-log4j12</artifactId>

<version>1.7.2</version>

</dependency>

<dependency>

<groupId>com.thoughtworks.xstream</groupId>

<artifactId>xstream</artifactId>

<version>1.2.2</version>

</dependency>

<dependency>

<groupId>ant</groupId>

<artifactId>ant</artifactId>

<version>1.7.0</version>

</dependency>

<!-- Test -->

<dependency>

<groupId>junit</groupId>

<artifactId>junit</artifactId>

<version>4.7</version>

<scope>test</scope>

</dependency>

<dependency>

<groupId>aopalliance</groupId>

<artifactId>aopalliance</artifactId>

<version>1.0</version>

</dependency>

<dependency>

<groupId>commons-dbcp</groupId>

<artifactId>commons-dbcp</artifactId>

<version>1.3</version>

</dependency>

<dependency>

<groupId>commons-fileupload</groupId>

<artifactId>commons-fileupload</artifactId>

<version>1.3</version>

</dependency>

<!--

<dependency>

<groupId>commons-logging</groupId>

<artifactId>commons-logging</artifactId>

<version>1.1.3</version>

</dependency>

-->

<dependency>

<groupId>commons-pool</groupId>

<artifactId>commons-pool</artifactId>

<version>1.5.4</version>

</dependency>

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>jstl</artifactId>

<version>1.1.2</version>

</dependency>

<!--

<dependency>

<groupId>com.oracle</groupId>

<artifactId>ojdbc14</artifactId>

<version>10.2.0.3.0</version>

</dependency>

-->

<dependency>

<groupId>taglibs</groupId>

<artifactId>standard</artifactId>

<version>1.1.2</version>

</dependency>

<dependency>

<groupId>commons-codec</groupId>

<artifactId>commons-codec</artifactId>

<version>1.5</version>

</dependency>

<dependency>

<groupId>commons-lang</groupId>

<artifactId>commons-lang</artifactId>

<version>2.1</version>

</dependency>

<dependency>

<groupId>net.sf.ezmorph</groupId>

<artifactId>ezmorph</artifactId>

<version>1.0.6</version>

</dependency>

<dependency>

<groupId>net.sf.json-lib</groupId>

<artifactId>json-lib</artifactId>

<version>2.3</version>

<classifier>jdk15</classifier>

</dependency>

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>servlet-api</artifactId>

<version>2.5</version>

<scope>provided</scope>

</dependency>

<dependency>

<groupId>org.json</groupId>

<artifactId>org.json</artifactId>

<version>chargebee-1.0</version>

</dependency>

<!-- json -->

<dependency>

<groupId>net.sf.json-lib</groupId>

<artifactId>json-lib</artifactId>

<version>2.4</version>

<classifier>jdk15</classifier>

</dependency>

<dependency>

<groupId>org.codehaus.jackson</groupId>

<artifactId>jackson-core-lgpl</artifactId>

<version>${org.codehaus.jackson}</version>

</dependency>

<dependency>

<groupId>org.codehaus.jackson</groupId>

<artifactId>jackson-mapper-lgpl</artifactId>

<version>${org.codehaus.jackson}</version>

</dependency>

<dependency>

<groupId>org.json</groupId>

<artifactId>json</artifactId>

<version>20140107</version>

</dependency>

<dependency>

<groupId>jaxen</groupId>

<artifactId>jaxen</artifactId>

<version>1.1.6</version>

</dependency>

<dependency>

<groupId>org.aspectj</groupId>

<artifactId>aspectjrt</artifactId>

<version>1.8.9</version>

</dependency>

<dependency>

<groupId>org.aspectj</groupId>

<artifactId>aspectjweaver</artifactId>

<version>1.8.9</version>

</dependency>

<!-- <dependency>

<groupId>commons-codec</groupId>

<artifactId>commons-codec</artifactId>

<version>1.9</version>

</dependency>

-->

<dependency>

<groupId>commons-logging</groupId>

<artifactId>commons-logging</artifactId>

<version>1.2</version>

</dependency>

<dependency>

<groupId>mysql</groupId>

<artifactId>mysql-connector-java</artifactId>

<version>5.1.38</version>

</dependency>

<!-- 阿里巴巴的druid数据源配置 -->

<dependency>

<groupId>com.alibaba</groupId>

<artifactId>druid</artifactId>

<version>1.0.18</version>

</dependency>

<!-- 文档处理所需的jar的依赖 -->

<dependency>

<groupId>commons-io</groupId>

<artifactId>commons-io</artifactId>

<version>2.4</version>

</dependency>

<dependency>

<groupId>org.apache.httpcomponents</groupId>

<artifactId>fluent-hc</artifactId>

<version>4.5.2</version>

</dependency>

<dependency>

<groupId>org.apache.httpcomponents</groupId>

<artifactId>httpclient</artifactId>

<version>4.5.2</version>

</dependency>

<dependency>

<groupId>org.apache.httpcomponents</groupId>

<artifactId>httpclient-cache</artifactId>

<version>4.5.2</version>

</dependency>

<dependency>

<groupId>org.apache.httpcomponents</groupId>

<artifactId>httpcore</artifactId>

<version>4.4.4</version>

</dependency>

<dependency>

<groupId>org.apache.httpcomponents</groupId>

<artifactId>httpclient-win</artifactId>

<version>4.5.2</version>

</dependency>

<dependency>

<groupId>org.apache.httpcomponents</groupId>

<artifactId>httpmime</artifactId>

<version>4.5.2</version>

</dependency>

<!-- dubbo -->

<dependency>

<groupId>com.alibaba</groupId>

<artifactId>dubbo</artifactId>

<version>2.5.3</version>

<exclusions>

<exclusion>

<artifactId>spring</artifactId>

<groupId>org.springframework</groupId>

</exclusion>

</exclusions>

</dependency>

<dependency>

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

<artifactId>zookeeper</artifactId>

<version>3.4.6</version>

<exclusions>

<exclusion>

<groupId>log4j</groupId>

<artifactId>log4j</artifactId>

</exclusion>

</exclusions>

</dependency>

<dependency>

<groupId>dom4j</groupId>

<artifactId>dom4j</artifactId>

<version>1.6.1</version>

</dependency>

<dependency>

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

<artifactId>zkclient</artifactId>

<version>0.1</version>

</dependency>

<dependency>

<groupId>com.dubbo</groupId>

<artifactId>dubbo-api</artifactId>

<version>1.0-SNAPSHOT</version>

</dependency>

</dependencies>

</project>

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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

<display-name>spring_Modle</display-name>

<session-config>

<session-timeout>30</session-timeout>

</session-config>

<context-param>

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

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

</context-param>

<context-param>

<param-name>log4jConfigLocation</param-name>

<param-value>classpath:log4j.properties</param-value>

</context-param>

<filter>

<filter-name>characterEncodingFilter</filter-name>

<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

<init-param>

<param-name>encoding</param-name>

<param-value>UTF-8</param-value>

</init-param>

<init-param>

<param-name>forceEncoding</param-name>

<param-value>true</param-value>

</init-param>

</filter>

<filter-mapping>

<filter-name>characterEncodingFilter</filter-name>

<url-pattern>*.action</url-pattern>

</filter-mapping>

<filter-mapping>

<filter-name>characterEncodingFilter</filter-name>

<url-pattern>*.jsp</url-pattern>

</filter-mapping>

<listener>

<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>

</listener>

<listener>

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

</listener>

<servlet>

<servlet-name>spring</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>

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

<param-value>classpath:context-dispatcher.xml</param-value>

</init-param>

</servlet>

<servlet-mapping>

<servlet-name>spring</servlet-name>

<url-pattern>*.action</url-pattern>

</servlet-mapping>

<welcome-file-list>

<welcome-file>index.jsp</welcome-file>

</welcome-file-list>

</web-app>

applicationContext.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:dubbo="http://code.alibabatech.com/schema/dubbo"

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

    http://code.alibabatech.com/schema/dubbo

    http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

<!-- 提供方应用信息,用于计算依赖关系 -->

<dubbo:application name="test_provider" />

<!-- 使用zookeeper注册中心暴露服务地址 -->

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

<!-- 用dubbo协议在20880端口暴露服务地址 -->

<dubbo:protocol name="dubbo" port="20880" />

<!-- 声明需要暴露的服务接口 -->

<dubbo:service interface="com.dubbo.service.TestService" ref="testService" />

<!-- 具体的实现bean -->

<bean id="testService" class="com.dubbo.service.impl.TestServiceImpl" />

</beans>

context-dispatcher.xml

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

<beans default-lazy-init="true"

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

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

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

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

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

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

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

xsi:schemaLocation=

       http://www.springframework.org/schema/beans  

       http://www.springframework.org/schema/beans/spring-beans-3.1.xsd

       http://www.springframework.org/schema/mvc  

       http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd  

       http://www.springframework.org/schema/context 

       http://www.springframework.org/schema/context/spring-context-4.0.xsd

       http://www.springframework.org/schema/aop

      http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">

<!-- 使用注解的包,包括子集 --><!-- http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd -->

<context:component-scan base-package="com.dubbo" />

<aop:aspectj-autoproxy/>

<!-- 通过注解,把URL映射到Controller上,该标签默认注册DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter-->

<mvc:annotation-driven>

<mvc:message-converters>

<bean class="org.springframework.http.converter.StringHttpMessageConverter">

<!--  <constructor-arg value="UTF-8" />-->

<property name="supportedMediaTypes">

<list>

<value>text/html;charset=UTF-8</value>

</list>

</property>

</bean>

</mvc:message-converters>

</mvc:annotation-driven>

<!-- 视图解析器 -->

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />

<property name="prefix" value="/WEB-INF/pages/" />

<property name="suffix" value=".jsp"></property>

</bean>

<bean id="defaultJsonView" class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"/>

<bean id="multipartResolver"

class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />

</beans>

新建TestServiceImpl类

package com.dubbo.service.impl;

import com.dubbo.service.TestService;

public class TestServiceImpl implements TestService {

public String sayHello(String name) {

return name + " service2 say hello word service2!";

}

}

注意:这里作为服务提供者名称为test_provider,注释很详细,就不一一介绍了,这个项目最终打包成dubbo-service.war放在tomcat或其他容器中运行

好了,经过这么配置之后,我们的项目编码配置部分就大功告成了!

maven编译下三个项目,将dubbo-provider和dubbo-consumer放到tomcat容器中,启动tomcat容器! 注意此过程中要配置启动zookeeper,不然dubbo去zookeeper注册中心暴露服务地址不成功啦!

四、配置启动zookeeper

最后要启动zookeeper,关于zookeeper的安装配置,可以参考:http://blog.csdn.net/tototuzuoquan/article/details/54003140

启动zookeeper !

再次启动tomcat容器,是不是就成功啦!我们来访问下http://127.0.0.1:8080/dubbo-consumer/test.action?name=toto,看下返回结果是不是正确啦!

其他dubbo相关的资料:

Dubbo:官网http://dubbo.io/

开发指南:http://dubbo.io/User+Guide-zh.htm

开发指南:http://dubbo.io/Developer+Guide-zh.htm

管理员指南:http://dubbo.io/Administrator+Guide-zh.htm

常见问题:http://dubbo.io/FAQ-zh.htm

Maven+SpringMVC+Dubbo+zookeeper 简单的入门demo配置相关推荐

  1. maven+springmvc+dubbo+zookeeper

    为什么要用dubbo? 还是让官方来解释吧: http://dubbo.io/User+Guide-zh.htm   http://dubbo.io/ 一般 nginx+tomcat | ----&g ...

  2. SSM+Maven+Dubbo+Zookeeper简单项目实战以及易错注意点

    最近为了熟悉Dubbo远程过程调用架构的使用,并结合SSM+Maven整合了简单的一套项目实战 直接看项目结构图 各模块介绍 dubbo-common:存放项目需要的公众类,像查询模型.数据库实体模型 ...

  3. springMVC + Dubbo + zooKeeper超详细 步骤

    linux 安装 zookeeper 在linux上安装ZooKeeper 第一步 安装jdk 第二步: 将Zookeeper 压缩包上传到linux 系统 第三步: 新建zookeeper目录 mk ...

  4. Spring+Dubbo+Zookeeper简单框架与使用

    为什么80%的码农都做不了架构师?>>>    例子参考地址:http://www.cnblogs.com/Javame/p/3632473.html 一.实例搭建 1.搭建框架前先 ...

  5. dubbo入门学习笔记之入门demo(基于普通maven项目)

    注:本笔记接dubbo入门学习笔记之环境准备继续记录; (四)开发服务提供者和消费者并让他们在启动时分别向注册中心注册和订阅服务 需求:订单服务中初始化订单功能需要调用用户服务的获取用户信息的接口(订 ...

  6. (五)springmvc+mybatis+dubbo+zookeeper分布式架构 整合 - maven构建根项目

    上一篇我们介绍<springmvc+mybatis+dubbo+zookeeper分布式架构 整合 - maven模块规划>,从今天开始,我们将对代码的每一个构建做详细的记录,能够帮助大家 ...

  7. Dubbo,入门Demo案列使用,框架原理,Zookeeper的使用,安装监控中心和管理控制台,service,provider,comsumer三个项目的Demo

    dubbo 分布式企业级分布式框架 https://dubbo.gitbooks.io/dubbo-user-book/content/preface/background.html 二,背景 三,d ...

  8. Dubbo入门Demo

    2019独角兽企业重金招聘Python工程师标准>>> 1.Dubbo简单介绍 Dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方 ...

  9. dubbo web工程示例_分布式开发-Zooker+dubbo入门-Demo

    作者:知了堂-刘阳 1.什么是SOA架构 SOA 是Service-Oriented Architecture的首字母简称,它是一个面向服务的架构模式(俗称:分布式:面服务的分布式) 为什么互联网项目 ...

最新文章

  1. 产业丨一文读懂人工智能产业链,未来10年2000亿美元市场
  2. 解决开机自检D盘问题
  3. 正则表达式注意事项以及常用方法
  4. 逻辑门电路的知识点归纳
  5. 思科模拟器:[1]安装及汉化详解
  6. 【视频特辑】数据分析师必备,快速制作一张强大好用的大宽表
  7. [转]Android应用的自动更新
  8. Mac OS git多次需要输入用户名密码config解决
  9. uniapp中获取元素页面信息的方法
  10. Android面试简历
  11. 十分好用PDF转换成PPT转换器
  12. springboot教务评教系统毕业设计源码252116
  13. navigate实现页面跳转及传参
  14. 控制计算机桌面图标,(1)在桌面上显示“计算机”“控制面板”图标,然后隐藏“控制面板”图标。...
  15. 【c语言】高级篇学习笔记
  16. C语言课程设计——宾馆管理系统
  17. 华擎计算机主板参数,【华擎Z390参数】华擎Z390系列主板参数-ZOL中关村在线
  18. 带你一起Piu Piu Piu
  19. 应试教育中的孩子长不好
  20. 我的第一个Chrome插件:天气预报应用

热门文章

  1. python 错误处理 assert
  2. Django中pipeline操作Redis数据库
  3. VTK:方向标记用法实战
  4. wxWidgets:wxGridUpdateLocker类用法
  5. wxWidgets:wxEraseEvent类用法
  6. boost::movelib::unique_ptr相关用法的测试程序
  7. boost::math模块计算贝塞尔函数的零点的测试程序
  8. boost::hana::detail::ebo用法的测试程序
  9. boost::hana::find用法的测试程序
  10. boost::hawick_circuits用法的测试程序