Manven+Eclipse+zookeeper搭建分布式架构

 要搭建项目,先要将项目拆分成N层,将服务(service)层独自放在A台服务器专门提供服务,zookeepek也可以单独放在一台服务器B,A服务器运行的服务要注册到B的zk注册中心,将界面层和逻辑处理放在同一层,该层只运行(springMvc+spring),该层也单独放在C台服务器。请求到C服务器,请求去B注册中心找服务。找到对应服务,返回结果到界面。

一个完整的项目可以简单拆分成:实体Po、servicedao、服务(service)、web呈现界面。简单点理解就是提供者和消费者的关系。提供者:服务(service),消费者:web呈现界面。

1、  建立实体Po Maven项目层。

该项目pom.xml不引用其他jar包,默认配置。

2、  建立servicedaoMaven项目层。

该项目要引用实体Po项目中的实体po,还要引用其他jar包,所以都在该项目的pom.xml中配置jar包的引用。

该项目的pom.xml文件配置

[html]  view plain  copy
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  2.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
  3.     <modelVersion>4.0.0</modelVersion>  
  4.   
  5.     <groupId>end.gx.servicedao</groupId>  
  6.     <artifactId>servicedao</artifactId>  
  7.     <version>0.0.1-SNAPSHOT</version>  
  8.     <packaging>jar</packaging>  
  9.   
  10.     <name>servicedao</name>  
  11.     <url>http://maven.apache.org</url>  
  12.   
  13.     <properties>  
  14.         <!-- spring版本号 -->  
  15.         <spring.version>3.2.4.RELEASE</spring.version>  
  16.         <!-- mybatis版本号 -->  
  17.         <mybatis.version>3.2.4</mybatis.version>  
  18.         <!-- log4j日志文件管理包版本 -->  
  19.         <slf4j.version>1.6.6</slf4j.version>  
  20.         <log4j.version>1.2.17</log4j.version>  
  21.         <fastjson.version>1.1.33</fastjson.version>  
  22.         <commons-codec.version>1.6</commons-codec.version>  
  23.         <commons-lang.version>2.5</commons-lang.version>  
  24.         <zookeeper_version>3.3.3</zookeeper_version>  
  25.         <zkclient_version>0.1</zkclient_version>  
  26.         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
  27.     </properties>  
  28.   
  29.     <dependencies>  
  30.   
  31.         <!-- 引入实体po -->  
  32.         <dependency>  
  33.             <groupId>end.gx.entity</groupId>  
  34.             <artifactId>po</artifactId>  
  35.             <version>0.0.1-SNAPSHOT</version>  
  36.         </dependency>  
  37.   
  38.         <!-- spring框架 -->  
  39.         <dependency>  
  40.             <groupId>org.springframework</groupId>  
  41.             <artifactId>spring-core</artifactId>  
  42.             <version>${spring.version}</version>  
  43.         </dependency>  
  44.   
  45.         <dependency>  
  46.             <groupId>org.springframework</groupId>  
  47.             <artifactId>spring-web</artifactId>  
  48.             <version>${spring.version}</version>  
  49.         </dependency>  
  50.   
  51.         <dependency>  
  52.             <groupId>org.springframework</groupId>  
  53.             <artifactId>spring-oxm</artifactId>  
  54.             <version>${spring.version}</version>  
  55.         </dependency>  
  56.   
  57.         <dependency>  
  58.             <groupId>org.springframework</groupId>  
  59.             <artifactId>spring-tx</artifactId>  
  60.             <version>${spring.version}</version>  
  61.         </dependency>  
  62.   
  63.         <dependency>  
  64.             <groupId>org.springframework</groupId>  
  65.             <artifactId>spring-webmvc</artifactId>  
  66.             <version>${spring.version}</version>  
  67.         </dependency>  
  68.   
  69.         <dependency>  
  70.             <groupId>org.springframework</groupId>  
  71.             <artifactId>spring-aop</artifactId>  
  72.             <version>${spring.version}</version>  
  73.         </dependency>  
  74.   
  75.         <dependency>  
  76.             <groupId>org.springframework</groupId>  
  77.             <artifactId>spring-jdbc</artifactId>  
  78.             <version>${spring.version}</version>  
  79.         </dependency>  
  80.   
  81.         <dependency>  
  82.             <groupId>org.springframework</groupId>  
  83.             <artifactId>spring-context-support</artifactId>  
  84.             <version>${spring.version}</version>  
  85.         </dependency>  
  86.   
  87.         <dependency>  
  88.             <groupId>org.springframework</groupId>  
  89.             <artifactId>spring-test</artifactId>  
  90.             <version>${spring.version}</version>  
  91.         </dependency>  
  92.   
  93.         <dependency>  
  94.             <groupId>org.springframework</groupId>  
  95.             <artifactId>spring-aspects</artifactId>  
  96.             <version>${spring.version}</version>  
  97.         </dependency>  
  98.         <!-- springframe end -->  
  99.           
  100.         <!-- mybatis核心包 -->  
  101.         <dependency>  
  102.             <groupId>org.mybatis</groupId>  
  103.             <artifactId>mybatis</artifactId>  
  104.             <version>${mybatis.version}</version>  
  105.         </dependency>  
  106.         <!-- mybatis/spring包 -->  
  107.         <dependency>  
  108.             <groupId>org.mybatis</groupId>  
  109.             <artifactId>mybatis-spring</artifactId>  
  110.             <version>1.2.2</version>  
  111.         </dependency>  
  112.         <!-- mysql驱动包 -->  
  113.         <dependency>  
  114.             <groupId>mysql</groupId>  
  115.             <artifactId>mysql-connector-java</artifactId>  
  116.             <version>5.1.22</version>  
  117.         </dependency>  
  118.   
  119.         <!-- junit测试包 -->  
  120.         <dependency>  
  121.             <groupId>junit</groupId>  
  122.             <artifactId>junit</artifactId>  
  123.             <version>4.11</version>  
  124.             <scope>test</scope>  
  125.         </dependency>  
  126.   
  127.         <!-- 阿里巴巴数据源包 -->  
  128.         <dependency>  
  129.             <groupId>com.alibaba</groupId>  
  130.             <artifactId>druid</artifactId>  
  131.             <version>1.0.2</version>  
  132.         </dependency>  
  133.         <!-- json数据 -->  
  134.         <dependency>  
  135.             <groupId>com.alibaba</groupId>  
  136.             <artifactId>fastjson</artifactId>  
  137.             <version>${fastjson.version}</version>  
  138.         </dependency>  
  139.         <dependency>  
  140.             <groupId>org.codehaus.jackson</groupId>  
  141.             <artifactId>jackson-mapper-asl</artifactId>  
  142.             <version>1.9.13</version>  
  143.         </dependency>  
  144.         <dependency>  
  145.             <groupId>com.google.code.gson</groupId>  
  146.             <artifactId>gson</artifactId>  
  147.             <version>2.8.0</version>  
  148.         </dependency>  
  149.         <!--json-lib -->  
  150.         <dependency>  
  151.             <groupId>net.sf.json-lib</groupId>  
  152.             <artifactId>json-lib</artifactId>  
  153.             <version>2.4</version>  
  154.             <classifier>jdk15</classifier>  
  155.         </dependency>  
  156.   
  157.         <!-- 日常使用 -->  
  158.         <dependency>  
  159.             <groupId>commons-fileupload</groupId>  
  160.             <artifactId>commons-fileupload</artifactId>  
  161.             <version>1.3.1</version>  
  162.         </dependency>  
  163.   
  164.         <dependency>  
  165.             <groupId>commons-lang</groupId>  
  166.             <artifactId>commons-lang</artifactId>  
  167.             <version>${commons-lang.version}</version>  
  168.         </dependency>  
  169.   
  170.         <dependency>  
  171.             <groupId>org.apache.commons</groupId>  
  172.             <artifactId>commons-lang3</artifactId>  
  173.             <version>3.4</version>  
  174.         </dependency>  
  175.   
  176.         <dependency>  
  177.             <groupId>commons-codec</groupId>  
  178.             <artifactId>commons-codec</artifactId>  
  179.             <version>${commons-codec.version}</version>  
  180.         </dependency>  
  181.         <!-- 解决tomcat没有此包bug -->  
  182.         <dependency>  
  183.             <groupId>javax.servlet</groupId>  
  184.             <artifactId>jstl</artifactId>  
  185.             <version>1.2</version>  
  186.             <scope>runtime</scope>  
  187.         </dependency>  
  188.   
  189.         <dependency>  
  190.             <groupId>javax.servlet</groupId>  
  191.             <artifactId>servlet-api</artifactId>  
  192.             <version>2.5</version>  
  193.             <scope>provided</scope>  
  194.         </dependency>  
  195.   
  196.         <dependency>  
  197.             <groupId>javax.servlet.jsp</groupId>  
  198.             <artifactId>jsp-api</artifactId>  
  199.             <version>2.0</version>  
  200.             <scope>provided</scope>  
  201.         </dependency>  
  202.   
  203.         <!-- 日志文件管理包 -->  
  204.         <!-- log start -->  
  205.         <dependency>  
  206.             <groupId>log4j</groupId>  
  207.             <artifactId>log4j</artifactId>  
  208.             <version>${log4j.version}</version>  
  209.         </dependency>  
  210.         <dependency>  
  211.             <groupId>org.slf4j</groupId>  
  212.             <artifactId>slf4j-api</artifactId>  
  213.             <version>${slf4j.version}</version>  
  214.         </dependency>  
  215.         <dependency>  
  216.             <groupId>org.slf4j</groupId>  
  217.             <artifactId>slf4j-log4j12</artifactId>  
  218.             <version>${slf4j.version}</version>  
  219.         </dependency>  
  220.         <!-- log end -->  
  221.   
  222.         <!-- freemarker -->  
  223.         <dependency>  
  224.             <groupId>org.freemarker</groupId>  
  225.             <artifactId>freemarker</artifactId>  
  226.             <version>2.3.22</version>  
  227.         </dependency>  
  228.   
  229.         <!-- 分页工具 -->  
  230.         <dependency>  
  231.             <groupId>jsptags</groupId>  
  232.             <artifactId>pager-taglib</artifactId>  
  233.             <version>2.0</version>  
  234.         </dependency>  
  235.         <!-- 邮件 -->  
  236.         <dependency>  
  237.             <groupId>javax.mail</groupId>  
  238.             <artifactId>mail</artifactId>  
  239.             <version>1.4</version>  
  240.         </dependency>  
  241.         <!-- 使用缓存解决JSSDK -->  
  242.         <dependency>  
  243.             <groupId>net.sf.ehcache</groupId>  
  244.             <artifactId>ehcache</artifactId>  
  245.             <version>2.9.1</version>  
  246.         </dependency>  
  247.     </dependencies>  
  248. </project>  

3、  建立提供者(service)MavenWeb项目

该项目要引用实体Po和servicedao和其他jar包,最主要的是各种配置文件要配置正确。

先是pom.xml的配置:

[html]  view plain  copy
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  2.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  
  3.     <modelVersion>4.0.0</modelVersion>  
  4.     <groupId>end.gx.service</groupId>  
  5.     <artifactId>service</artifactId>  
  6.     <packaging>war</packaging>  
  7.     <version>0.0.1-SNAPSHOT</version>  
  8.     <name>service Maven Webapp</name>  
  9.     <url>http://maven.apache.org</url>  
  10.   
  11.   
  12.     <properties>  
  13.         <!-- spring版本号 -->  
  14.         <spring.version>3.2.4.RELEASE</spring.version>  
  15.         <!-- mybatis版本号 -->  
  16.         <mybatis.version>3.2.4</mybatis.version>  
  17.         <!-- log4j日志文件管理包版本 -->  
  18.         <slf4j.version>1.6.6</slf4j.version>  
  19.         <log4j.version>1.2.17</log4j.version>  
  20.         <fastjson.version>1.1.33</fastjson.version>  
  21.         <commons-codec.version>1.6</commons-codec.version>  
  22.         <commons-lang.version>2.5</commons-lang.version>  
  23.         <zookeeper_version>3.3.3</zookeeper_version>  
  24.         <zkclient_version>0.1</zkclient_version>  
  25.         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
  26.     </properties>  
  27.     <dependencies>  
  28.         <!-- po -->  
  29.         <dependency>  
  30.             <groupId>end.gx.entity</groupId>  
  31.             <artifactId>po</artifactId>  
  32.             <version>0.0.1-SNAPSHOT</version>  
  33.         </dependency>  
  34.   
  35.         <!-- servicedao -->  
  36.         <dependency>  
  37.             <groupId>end.gx.servicedao</groupId>  
  38.             <artifactId>servicedao</artifactId>  
  39.             <version>0.0.1-SNAPSHOT</version>  
  40.         </dependency>  
  41.   
  42.         <!-- spring框架 -->  
  43.         <dependency>  
  44.             <groupId>org.springframework</groupId>  
  45.             <artifactId>spring-core</artifactId>  
  46.             <version>${spring.version}</version>  
  47.         </dependency>  
  48.   
  49.         <dependency>  
  50.             <groupId>org.springframework</groupId>  
  51.             <artifactId>spring-web</artifactId>  
  52.             <version>${spring.version}</version>  
  53.         </dependency>  
  54.   
  55.         <dependency>  
  56.             <groupId>org.springframework</groupId>  
  57.             <artifactId>spring-oxm</artifactId>  
  58.             <version>${spring.version}</version>  
  59.         </dependency>  
  60.   
  61.         <dependency>  
  62.             <groupId>org.springframework</groupId>  
  63.             <artifactId>spring-tx</artifactId>  
  64.             <version>${spring.version}</version>  
  65.         </dependency>  
  66.   
  67.         <dependency>  
  68.             <groupId>org.springframework</groupId>  
  69.             <artifactId>spring-webmvc</artifactId>  
  70.             <version>${spring.version}</version>  
  71.         </dependency>  
  72.   
  73.         <dependency>  
  74.             <groupId>org.springframework</groupId>  
  75.             <artifactId>spring-aop</artifactId>  
  76.             <version>${spring.version}</version>  
  77.         </dependency>  
  78.   
  79.         <dependency>  
  80.             <groupId>org.springframework</groupId>  
  81.             <artifactId>spring-jdbc</artifactId>  
  82.             <version>${spring.version}</version>  
  83.         </dependency>  
  84.   
  85.         <dependency>  
  86.             <groupId>org.springframework</groupId>  
  87.             <artifactId>spring-context-support</artifactId>  
  88.             <version>${spring.version}</version>  
  89.         </dependency>  
  90.   
  91.         <dependency>  
  92.             <groupId>org.springframework</groupId>  
  93.             <artifactId>spring-test</artifactId>  
  94.             <version>${spring.version}</version>  
  95.         </dependency>  
  96.   
  97.         <dependency>  
  98.             <groupId>org.springframework</groupId>  
  99.             <artifactId>spring-aspects</artifactId>  
  100.             <version>${spring.version}</version>  
  101.         </dependency>  
  102.         <!-- springframe end -->  
  103.   
  104.         <!-- dubbo -->  
  105.         <dependency>  
  106.             <groupId>com.alibaba</groupId>  
  107.             <artifactId>dubbo</artifactId>  
  108.             <version>2.5.3</version>  
  109.             <exclusions>  
  110.                 <exclusion>  
  111.                     <groupId>org.springframework</groupId>  
  112.                     <artifactId>spring</artifactId>  
  113.                 </exclusion>  
  114.             </exclusions>  
  115.         </dependency>  
  116.           
  117.         <!--zookeeper -->  
  118.         <dependency>  
  119.             <groupId>org.apache.zookeeper</groupId>  
  120.             <artifactId>zookeeper</artifactId>  
  121.             <version>3.3.3</version>  
  122.         </dependency>  
  123.         <dependency>  
  124.             <groupId>com.github.sgroschupf</groupId>  
  125.             <artifactId>zkclient</artifactId>  
  126.             <version>0.1</version>  
  127.         </dependency>  
  128.         <dependency>  
  129.             <groupId>org.codehaus.xfire</groupId>  
  130.             <artifactId>xfire-all</artifactId>  
  131.             <version>1.2.6</version>  
  132.             <exclusions>  
  133.                 <exclusion>  
  134.                     <groupId>org.springframework</groupId>  
  135.                     <artifactId>spring</artifactId>  
  136.                 </exclusion>  
  137.             </exclusions>  
  138.         </dependency>  
  139.           
  140.         <!-- mybatis核心包 -->  
  141.         <dependency>  
  142.             <groupId>org.mybatis</groupId>  
  143.             <artifactId>mybatis</artifactId>  
  144.             <version>${mybatis.version}</version>  
  145.         </dependency>  
  146.         <!-- mybatis/spring包 -->  
  147.         <dependency>  
  148.             <groupId>org.mybatis</groupId>  
  149.             <artifactId>mybatis-spring</artifactId>  
  150.             <version>1.2.2</version>  
  151.         </dependency>  
  152.         <!-- mysql驱动包 -->  
  153.         <dependency>  
  154.             <groupId>mysql</groupId>  
  155.             <artifactId>mysql-connector-java</artifactId>  
  156.             <version>5.1.22</version>  
  157.         </dependency>  
  158.   
  159.         <!-- junit测试包 -->  
  160.         <dependency>  
  161.             <groupId>junit</groupId>  
  162.             <artifactId>junit</artifactId>  
  163.             <version>4.11</version>  
  164.             <scope>test</scope>  
  165.         </dependency>  
  166.   
  167.         <!-- 阿里巴巴数据源包 -->  
  168.         <dependency>  
  169.             <groupId>com.alibaba</groupId>  
  170.             <artifactId>druid</artifactId>  
  171.             <version>1.0.2</version>  
  172.         </dependency>  
  173.         <!-- json数据 -->  
  174.         <dependency>  
  175.             <groupId>com.alibaba</groupId>  
  176.             <artifactId>fastjson</artifactId>  
  177.             <version>${fastjson.version}</version>  
  178.         </dependency>  
  179.         <dependency>  
  180.             <groupId>org.codehaus.jackson</groupId>  
  181.             <artifactId>jackson-mapper-asl</artifactId>  
  182.             <version>1.9.13</version>  
  183.         </dependency>  
  184.         <dependency>  
  185.             <groupId>com.google.code.gson</groupId>  
  186.             <artifactId>gson</artifactId>  
  187.             <version>2.8.0</version>  
  188.         </dependency>  
  189.         <!--json-lib -->  
  190.         <dependency>  
  191.             <groupId>net.sf.json-lib</groupId>  
  192.             <artifactId>json-lib</artifactId>  
  193.             <version>2.4</version>  
  194.             <classifier>jdk15</classifier>  
  195.         </dependency>  
  196.   
  197.         <!-- 日常使用 -->  
  198.         <dependency>  
  199.             <groupId>commons-fileupload</groupId>  
  200.             <artifactId>commons-fileupload</artifactId>  
  201.             <version>1.3.1</version>  
  202.         </dependency>  
  203.   
  204.         <dependency>  
  205.             <groupId>commons-lang</groupId>  
  206.             <artifactId>commons-lang</artifactId>  
  207.             <version>${commons-lang.version}</version>  
  208.         </dependency>  
  209.   
  210.         <dependency>  
  211.             <groupId>org.apache.commons</groupId>  
  212.             <artifactId>commons-lang3</artifactId>  
  213.             <version>3.4</version>  
  214.         </dependency>  
  215.   
  216.         <dependency>  
  217.             <groupId>commons-codec</groupId>  
  218.             <artifactId>commons-codec</artifactId>  
  219.             <version>${commons-codec.version}</version>  
  220.         </dependency>  
  221.         <!-- 解决tomcat没有此包bug -->  
  222.         <dependency>  
  223.             <groupId>javax.servlet</groupId>  
  224.             <artifactId>jstl</artifactId>  
  225.             <version>1.2</version>  
  226.             <scope>runtime</scope>  
  227.         </dependency>  
  228.   
  229.         <dependency>  
  230.             <groupId>javax.servlet</groupId>  
  231.             <artifactId>servlet-api</artifactId>  
  232.             <version>2.5</version>  
  233.             <scope>provided</scope>  
  234.         </dependency>  
  235.   
  236.         <dependency>  
  237.             <groupId>javax.servlet.jsp</groupId>  
  238.             <artifactId>jsp-api</artifactId>  
  239.             <version>2.0</version>  
  240.             <scope>provided</scope>  
  241.         </dependency>  
  242.   
  243.         <!-- 日志文件管理包 -->  
  244.         <!-- log start -->  
  245.         <dependency>  
  246.             <groupId>log4j</groupId>  
  247.             <artifactId>log4j</artifactId>  
  248.             <version>${log4j.version}</version>  
  249.         </dependency>  
  250.         <dependency>  
  251.             <groupId>org.slf4j</groupId>  
  252.             <artifactId>slf4j-api</artifactId>  
  253.             <version>${slf4j.version}</version>  
  254.         </dependency>  
  255.         <dependency>  
  256.             <groupId>org.slf4j</groupId>  
  257.             <artifactId>slf4j-log4j12</artifactId>  
  258.             <version>${slf4j.version}</version>  
  259.         </dependency>  
  260.         <!-- log end -->  
  261.   
  262.         <!-- freemarker -->  
  263.         <dependency>  
  264.             <groupId>org.freemarker</groupId>  
  265.             <artifactId>freemarker</artifactId>  
  266.             <version>2.3.22</version>  
  267.         </dependency>  
  268.   
  269.         <!-- 分页工具 -->  
  270.         <dependency>  
  271.             <groupId>jsptags</groupId>  
  272.             <artifactId>pager-taglib</artifactId>  
  273.             <version>2.0</version>  
  274.         </dependency>  
  275.         <!-- 邮件 -->  
  276.         <dependency>  
  277.             <groupId>javax.mail</groupId>  
  278.             <artifactId>mail</artifactId>  
  279.             <version>1.4</version>  
  280.         </dependency>  
  281.         <!-- 使用缓存解决JSSDK -->  
  282.         <dependency>  
  283.             <groupId>net.sf.ehcache</groupId>  
  284.             <artifactId>ehcache</artifactId>  
  285.             <version>2.9.1</version>  
  286.         </dependency>  
  287.     </dependencies>  
  288.     <build>  
  289.         <finalName>service</finalName>  
  290.     </build>  
  291. </project>  

接着applicationContext.xml配置:

[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans  
  3.     xmlns="http://www.springframework.org/schema/beans"  
  4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  5.     xmlns:p="http://www.springframework.org/schema/p"  
  6.     xmlns:context="http://www.springframework.org/schema/context"  
  7.     xmlns:aop="http://www.springframework.org/schema/aop"  
  8.     xmlns:tx="http://www.springframework.org/schema/tx"    
  9.     xsi:schemaLocation="  
  10.     http://www.springframework.org/schema/tx  
  11.     http://www.springframework.org/schema/tx/spring-tx-3.1.xsd  
  12.     http://www.springframework.org/schema/aop     
  13.     http://www.springframework.org/schema/aop/spring-aop-3.1.xsd  
  14.     http://www.springframework.org/schema/context    
  15.     http://www.springframework.org/schema/context/spring-context-3.1.xsd    
  16.     http://www.springframework.org/schema/beans   
  17.     http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">  
  18.     <!-- 开启注解 -->  
  19.     <context:annotation-config />  
  20.     <!-- 自动扫描(service),(dao) -->  
  21.     <context:component-scan base-package="end.gx.dao,end.gx.service">  
  22.         <context:include-filter type="annotation" expression="org.springframework.stereotype.Service" />  
  23.         <context:include-filter type="annotation" expression="org.springframework.stereotype.Repository" />  
  24.     </context:component-scan>  
  25. </beans>  
再接着spring-mybatis.xml和 jdbc.properties 配置:

jdbc.properties

[html]  view plain  copy
  1. driverClassName=com.mysql.jdbc.Driver  
  2. url=jdbc:mysql://192.168.3.16:3306/hotelmanagementsystem?useUnicode=true&characterEncoding=utf-8  
  3. username=root  
  4. password=123  
  5. validationQuery=SELECT 1  

spring-mybatis.xml:

[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans  
  3.     xmlns="http://www.springframework.org/schema/beans"  
  4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  5.     xmlns:p="http://www.springframework.org/schema/p"  
  6.     xmlns:context="http://www.springframework.org/schema/context"  
  7.     xmlns:aop="http://www.springframework.org/schema/aop"  
  8.     xmlns:tx="http://www.springframework.org/schema/tx"    
  9.     xsi:schemaLocation="  
  10.     http://www.springframework.org/schema/tx  
  11.     http://www.springframework.org/schema/tx/spring-tx-3.1.xsd  
  12.     http://www.springframework.org/schema/aop     
  13.     http://www.springframework.org/schema/aop/spring-aop-3.1.xsd  
  14.     http://www.springframework.org/schema/context    
  15.     http://www.springframework.org/schema/context/spring-context-3.1.xsd    
  16.     http://www.springframework.org/schema/beans   
  17.     http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">  
  18.       
  19.     <!-- properties配置文件 -->    
  20.     <bean id="dbProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
  21.          <!-- 是否忽略不可解析的 -->    
  22.         <property name="ignoreUnresolvablePlaceholders" value="true" />  
  23.          <property name="locations">    
  24.             <list>    
  25.                 <value>classpath:jdbc.properties</value>    
  26.             </list>    
  27.         </property>    
  28.     </bean>  
  29.       
  30.     <!-- ========================================配置数据源========================================= -->  
  31.     <!-- 配置数据源,使用的是alibaba的Druid(德鲁伊)数据源 -->  
  32.     <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">  
  33.         <property name="url" value="${url}" />  
  34.         <property name="username" value="${username}" />  
  35.         <property name="password" value="${password}" />  
  36.         <!-- 初始化连接大小 -->  
  37.         <property name="initialSize" value="0" />  
  38.         <!-- 连接池最大使用连接数量 -->  
  39.         <property name="maxActive" value="20" />  
  40.         <!-- 连接池最大空闲 -->  
  41.         <property name="maxIdle" value="20" />  
  42.         <!-- 连接池最小空闲 -->  
  43.         <property name="minIdle" value="0" />  
  44.         <!-- 获取连接最大等待时间 -->  
  45.         <property name="maxWait" value="60000" />  
  46.         <property name="validationQuery" value="${validationQuery}" />  
  47.         <property name="testOnBorrow" value="false" />  
  48.         <property name="testOnReturn" value="false" />  
  49.         <property name="testWhileIdle" value="true" />  
  50.         <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->  
  51.         <property name="timeBetweenEvictionRunsMillis" value="60000" />  
  52.         <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->  
  53.         <property name="minEvictableIdleTimeMillis" value="25200000" />  
  54.         <!-- 打开removeAbandoned功能 -->  
  55.         <property name="removeAbandoned" value="true" />  
  56.         <!-- 1800秒,也就是30分钟 -->  
  57.         <property name="removeAbandonedTimeout" value="1800" />  
  58.         <!-- 关闭abanded连接时输出错误日志 -->  
  59.         <property name="logAbandoned" value="true" />  
  60.         <!-- 监控数据库 -->  
  61.         <!-- <property name="filters" value="stat" /> -->  
  62.         <property name="filters" value="mergeStat" />  
  63.     </bean>  
  64.       
  65.     <!-- ========================================针对myBatis的配置项============================== -->  
  66.     <!-- 配置sqlSessionFactory -->  
  67.     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
  68.         <!-- 实例化sqlSessionFactory时需要使用上述配置好的数据源以及SQL映射文件 -->  
  69.         <property name="dataSource" ref="dataSource" />  
  70.         <property name="configLocation" value="classpath:mybatis.cofig.xml"/>  
  71.         <!-- 自动扫描Mybatis的Mapper.xml文件 -->  
  72.         <property name="mapperLocations" value="classpath:end/gx/mapping/*.xml" />  
  73.     </bean>  
  74.       
  75.     <!-- 配置扫描器 -->  
  76.     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
  77.         <!-- 扫描com.fangjian.dao这个包以及它的子包下的所有映射接口类 -->  
  78.         <property name="basePackage" value="end.gx.dao" />  
  79.         <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />  
  80.     </bean>  
  81.       
  82.     <!-- 配置事务管理器 -->  
  83.     <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
  84.         <property name="dataSource" ref="dataSource" />  
  85.     </bean>  
  86.       
  87.     <!-- 拦截器方式配置事物 -->  
  88.     <tx:advice id="transactionAdvice" transaction-manager="transactionManager">  
  89.         <tx:attributes>  
  90.             <tx:method name="add*" propagation="REQUIRED" />  
  91.             <tx:method name="append*" propagation="REQUIRED" />  
  92.             <tx:method name="insert*" propagation="REQUIRED" />  
  93.             <tx:method name="save*" propagation="REQUIRED" />  
  94.             <tx:method name="update*" propagation="REQUIRED" />  
  95.             <tx:method name="modify*" propagation="REQUIRED" />  
  96.             <tx:method name="edit*" propagation="REQUIRED" />  
  97.             <tx:method name="delete*" propagation="REQUIRED" />  
  98.             <tx:method name="remove*" propagation="REQUIRED" />  
  99.             <tx:method name="repair" propagation="REQUIRED" />  
  100.             <tx:method name="delAndRepair" propagation="REQUIRED" />  
  101.             <tx:method name="get*" propagation="SUPPORTS" />  
  102.             <tx:method name="find*" propagation="SUPPORTS" />  
  103.             <tx:method name="load*" propagation="SUPPORTS" />  
  104.             <tx:method name="search*" propagation="SUPPORTS" />  
  105.             <tx:method name="datagrid*" propagation="SUPPORTS" />  
  106.             <tx:method name="*" propagation="SUPPORTS" />  
  107.         </tx:attributes>  
  108.     </tx:advice>  
  109.     <aop:config>  
  110.         <aop:pointcut id="transactionPointcut" expression="execution(* com.gx.service_dao.service..*Impl.*(..))" />     
  111.         <aop:advisor pointcut-ref="transactionPointcut" advice-ref="transactionAdvice" />  
  112.     </aop:config>  
  113.     <!-- 配置druid监控spring jdbc -->  
  114.     <bean id="druid-stat-interceptor" class="com.alibaba.druid.support.spring.stat.DruidStatInterceptor"></bean>  
  115.     <bean id="druid-stat-pointcut" class="org.springframework.aop.support.JdkRegexpMethodPointcut" scope="prototype">  
  116.         <property name="patterns">  
  117.             <list>  
  118.                 <value>com.gx.service_dao.service.*</value>  
  119.             </list>  
  120.         </property>  
  121.     </bean>  
  122.     <aop:config>  
  123.         <aop:advisor advice-ref="druid-stat-interceptor" pointcut-ref="druid-stat-pointcut" />  
  124.     </aop:config>  
  125.       
  126.     </beans>  

再有spring-dubbo-provider.xml配置:

[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  4.     xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"  
  5.     xsi:schemaLocation="http://www.springframework.org/schema/beans            
  6.     http://www.springframework.org/schema/beans/spring-beans.xsd            
  7.     http://code.alibabatech.com/schema/dubbo            
  8.     http://code.alibabatech.com/schema/dubbo/dubbo.xsd">  
  9. <dubbo:application name="dubbo-service" />  
  10. <!-- zookeeper所在服务器IP地址,本地的就是127.0.0.1 -->  
  11.     <dubbo:registry address="zookeeper://127.168.3.16:2181" />  
  12.     <dubbo:protocol name="dubbo" port="20880" />  
  13.          <!-- 可以有多个Service -->  
  14.     <dubbo:service interface="end.gx.service.UserService" ref="userService" />  
  15.         <!-- 可以有多个ServiceImpl -->  
  16.     <bean id="userService" class="end.gx.service.impl.UserServiceImpl" />  
  17. </beans>  

最后web.xml配置:

[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.     xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"  
  4.     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"  
  5.     id="WebApp_ID" version="2.5">  
  6.       
  7.   <display-name>Archetype Created Web Application</display-name>  
  8.     
  9.   <context-param>  
  10.         <param-name>contextConfigLocation</param-name>  
  11.         <param-value>  
  12.             classpath:applicationContext.xml,  
  13.             classpath:spring-mybatis.xml,  
  14.             classpath:spring-dubbo-provider.xml  
  15.         </param-value>  
  16.     </context-param>  
  17.   
  18.     <listener>  
  19.         <description>spring监听器</description>  
  20.         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  21.     </listener>  
  22. </web-app>  

4、建立消费方(web) MavenWeb项目

该项目要引用实体Po和servicedao,还要引用其他jar包。还有各种配置文件要正确配置。

先是pom.xml配置:

[html]  view plain  copy
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  2.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  
  3.     <modelVersion>4.0.0</modelVersion>  
  4.     <groupId>end.gx.service</groupId>  
  5.     <artifactId>serviceweb</artifactId>  
  6.     <packaging>war</packaging>  
  7.     <version>0.0.1-SNAPSHOT</version>  
  8.     <name>serviceweb Maven Webapp</name>  
  9.     <url>http://maven.apache.org</url>  
  10.   
  11.     <properties>  
  12.         <!-- spring版本号 -->  
  13.         <spring.version>3.2.4.RELEASE</spring.version>  
  14.         <!-- mybatis版本号 -->  
  15.         <mybatis.version>3.2.4</mybatis.version>  
  16.         <!-- log4j日志文件管理包版本 -->  
  17.         <slf4j.version>1.6.6</slf4j.version>  
  18.         <log4j.version>1.2.17</log4j.version>  
  19.         <fastjson.version>1.1.33</fastjson.version>  
  20.         <commons-codec.version>1.6</commons-codec.version>  
  21.         <commons-lang.version>2.5</commons-lang.version>  
  22.         <zookeeper_version>3.3.3</zookeeper_version>  
  23.         <zkclient_version>0.1</zkclient_version>  
  24.         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
  25.     </properties>  
  26.   
  27.     <dependencies>  
  28.   
  29.         <!-- 引用servicedao -->  
  30.         <dependency>  
  31.             <groupId>end.gx.servicedao</groupId>  
  32.             <artifactId>servicedao</artifactId>  
  33.             <version>0.0.1-SNAPSHOT</version>  
  34.         </dependency>  
  35.   
  36.         <!-- 引用实体po -->  
  37.         <dependency>  
  38.             <groupId>end.gx.entity</groupId>  
  39.             <artifactId>po</artifactId>  
  40.             <version>0.0.1-SNAPSHOT</version>  
  41.         </dependency>  
  42.   
  43.         <!-- spring框架 -->  
  44.         <dependency>  
  45.             <groupId>org.springframework</groupId>  
  46.             <artifactId>spring-core</artifactId>  
  47.             <version>${spring.version}</version>  
  48.         </dependency>  
  49.   
  50.         <dependency>  
  51.             <groupId>org.springframework</groupId>  
  52.             <artifactId>spring-web</artifactId>  
  53.             <version>${spring.version}</version>  
  54.         </dependency>  
  55.   
  56.         <dependency>  
  57.             <groupId>org.springframework</groupId>  
  58.             <artifactId>spring-oxm</artifactId>  
  59.             <version>${spring.version}</version>  
  60.         </dependency>  
  61.   
  62.         <dependency>  
  63.             <groupId>org.springframework</groupId>  
  64.             <artifactId>spring-tx</artifactId>  
  65.             <version>${spring.version}</version>  
  66.         </dependency>  
  67.   
  68.         <dependency>  
  69.             <groupId>org.springframework</groupId>  
  70.             <artifactId>spring-webmvc</artifactId>  
  71.             <version>${spring.version}</version>  
  72.         </dependency>  
  73.   
  74.         <dependency>  
  75.             <groupId>org.springframework</groupId>  
  76.             <artifactId>spring-aop</artifactId>  
  77.             <version>${spring.version}</version>  
  78.         </dependency>  
  79.   
  80.         <dependency>  
  81.             <groupId>org.springframework</groupId>  
  82.             <artifactId>spring-jdbc</artifactId>  
  83.             <version>${spring.version}</version>  
  84.         </dependency>  
  85.   
  86.         <dependency>  
  87.             <groupId>org.springframework</groupId>  
  88.             <artifactId>spring-context-support</artifactId>  
  89.             <version>${spring.version}</version>  
  90.         </dependency>  
  91.   
  92.         <dependency>  
  93.             <groupId>org.springframework</groupId>  
  94.             <artifactId>spring-test</artifactId>  
  95.             <version>${spring.version}</version>  
  96.         </dependency>  
  97.   
  98.         <dependency>  
  99.             <groupId>org.springframework</groupId>  
  100.             <artifactId>spring-aspects</artifactId>  
  101.             <version>${spring.version}</version>  
  102.         </dependency>  
  103.         <!-- springframe end -->  
  104.   
  105.   
  106.         <!-- dubbo -->  
  107.         <dependency>  
  108.             <groupId>com.alibaba</groupId>  
  109.             <artifactId>dubbo</artifactId>  
  110.             <version>2.5.3</version>  
  111.             <exclusions>  
  112.                 <exclusion>  
  113.                     <groupId>org.springframework</groupId>  
  114.                     <artifactId>spring</artifactId>  
  115.                 </exclusion>  
  116.             </exclusions>  
  117.         </dependency>  
  118.   
  119.         <!--zookeeper -->  
  120.         <dependency>  
  121.             <groupId>org.apache.zookeeper</groupId>  
  122.             <artifactId>zookeeper</artifactId>  
  123.             <version>3.3.3</version>  
  124.         </dependency>  
  125.         <dependency>  
  126.             <groupId>com.github.sgroschupf</groupId>  
  127.             <artifactId>zkclient</artifactId>  
  128.             <version>0.1</version>  
  129.         </dependency>  
  130.   
  131.         <!-- mybatis核心包 -->  
  132.         <dependency>  
  133.             <groupId>org.mybatis</groupId>  
  134.             <artifactId>mybatis</artifactId>  
  135.             <version>${mybatis.version}</version>  
  136.         </dependency>  
  137.         <!-- mybatis/spring包 -->  
  138.         <dependency>  
  139.             <groupId>org.mybatis</groupId>  
  140.             <artifactId>mybatis-spring</artifactId>  
  141.             <version>1.2.2</version>  
  142.         </dependency>  
  143.         <!-- mysql驱动包 -->  
  144.         <dependency>  
  145.             <groupId>mysql</groupId>  
  146.             <artifactId>mysql-connector-java</artifactId>  
  147.             <version>5.1.22</version>  
  148.         </dependency>  
  149.   
  150.         <!-- junit测试包 -->  
  151.         <dependency>  
  152.             <groupId>junit</groupId>  
  153.             <artifactId>junit</artifactId>  
  154.             <version>4.11</version>  
  155.             <scope>test</scope>  
  156.         </dependency>  
  157.   
  158.         <!-- 阿里巴巴数据源包 -->  
  159.         <dependency>  
  160.             <groupId>com.alibaba</groupId>  
  161.             <artifactId>druid</artifactId>  
  162.             <version>1.0.2</version>  
  163.         </dependency>  
  164.         <!-- json数据 -->  
  165.         <dependency>  
  166.             <groupId>com.alibaba</groupId>  
  167.             <artifactId>fastjson</artifactId>  
  168.             <version>${fastjson.version}</version>  
  169.         </dependency>  
  170.         <dependency>  
  171.             <groupId>org.codehaus.jackson</groupId>  
  172.             <artifactId>jackson-mapper-asl</artifactId>  
  173.             <version>1.9.13</version>  
  174.         </dependency>  
  175.         <dependency>  
  176.             <groupId>com.google.code.gson</groupId>  
  177.             <artifactId>gson</artifactId>  
  178.             <version>2.8.0</version>  
  179.         </dependency>  
  180.         <!--json-lib -->  
  181.         <dependency>  
  182.             <groupId>net.sf.json-lib</groupId>  
  183.             <artifactId>json-lib</artifactId>  
  184.             <version>2.4</version>  
  185.             <classifier>jdk15</classifier>  
  186.         </dependency>  
  187.   
  188.         <!-- 日常使用 -->  
  189.         <dependency>  
  190.             <groupId>commons-fileupload</groupId>  
  191.             <artifactId>commons-fileupload</artifactId>  
  192.             <version>1.3.1</version>  
  193.         </dependency>  
  194.   
  195.         <dependency>  
  196.             <groupId>commons-lang</groupId>  
  197.             <artifactId>commons-lang</artifactId>  
  198.             <version>${commons-lang.version}</version>  
  199.         </dependency>  
  200.   
  201.         <dependency>  
  202.             <groupId>org.apache.commons</groupId>  
  203.             <artifactId>commons-lang3</artifactId>  
  204.             <version>3.4</version>  
  205.         </dependency>  
  206.   
  207.         <dependency>  
  208.             <groupId>commons-codec</groupId>  
  209.             <artifactId>commons-codec</artifactId>  
  210.             <version>${commons-codec.version}</version>  
  211.         </dependency>  
  212.         <!-- 解决tomcat没有此包bug -->  
  213.         <dependency>  
  214.             <groupId>javax.servlet</groupId>  
  215.             <artifactId>jstl</artifactId>  
  216.             <version>1.2</version>  
  217.             <scope>runtime</scope>  
  218.         </dependency>  
  219.   
  220.         <dependency>  
  221.             <groupId>javax.servlet</groupId>  
  222.             <artifactId>servlet-api</artifactId>  
  223.             <version>2.5</version>  
  224.             <scope>provided</scope>  
  225.         </dependency>  
  226.   
  227.         <dependency>  
  228.             <groupId>javax.servlet.jsp</groupId>  
  229.             <artifactId>jsp-api</artifactId>  
  230.             <version>2.0</version>  
  231.             <scope>provided</scope>  
  232.         </dependency>  
  233.   
  234.         <!-- 日志文件管理包 -->  
  235.         <!-- log start -->  
  236.         <dependency>  
  237.             <groupId>log4j</groupId>  
  238.             <artifactId>log4j</artifactId>  
  239.             <version>${log4j.version}</version>  
  240.         </dependency>  
  241.         <dependency>  
  242.             <groupId>org.slf4j</groupId>  
  243.             <artifactId>slf4j-api</artifactId>  
  244.             <version>${slf4j.version}</version>  
  245.         </dependency>  
  246.         <dependency>  
  247.             <groupId>org.slf4j</groupId>  
  248.             <artifactId>slf4j-log4j12</artifactId>  
  249.             <version>${slf4j.version}</version>  
  250.         </dependency>  
  251.         <!-- log end -->  
  252.   
  253.         <!-- freemarker -->  
  254.         <dependency>  
  255.             <groupId>org.freemarker</groupId>  
  256.             <artifactId>freemarker</artifactId>  
  257.             <version>2.3.22</version>  
  258.         </dependency>  
  259.   
  260.         <!-- 分页工具 -->  
  261.         <dependency>  
  262.             <groupId>jsptags</groupId>  
  263.             <artifactId>pager-taglib</artifactId>  
  264.             <version>2.0</version>  
  265.         </dependency>  
  266.         <!-- 邮件 -->  
  267.         <dependency>  
  268.             <groupId>javax.mail</groupId>  
  269.             <artifactId>mail</artifactId>  
  270.             <version>1.4</version>  
  271.         </dependency>  
  272.         <!-- 使用缓存解决JSSDK -->  
  273.         <dependency>  
  274.             <groupId>net.sf.ehcache</groupId>  
  275.             <artifactId>ehcache</artifactId>  
  276.             <version>2.9.1</version>  
  277.         </dependency>  
  278.     </dependencies>  
  279.     <build>  
  280.         <finalName>serviceweb</finalName>  
  281.     </build>  
  282. </project>  

接着spring-mvc.xml配置:

[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"   
  3. xmlns:mvc="http://www.springframework.org/schema/mvc"   
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  5. xmlns:p="http://www.springframework.org/schema/p"   
  6. xmlns:context="http://www.springframework.org/schema/context"  
  7.         xsi:schemaLocation="http://www.springframework.org/schema/beans   
  8.         http://www.springframework.org/schema/beans/spring-beans-3.1.xsd   
  9.         http://www.springframework.org/schema/context   
  10.         http://www.springframework.org/schema/context/spring-context-3.1.xsd   
  11.         http://www.springframework.org/schema/mvc   
  12.         http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">  
  13.     <!-- 自动扫描controller包下的所有类,使其认为spring mvc的控制器 -->  
  14.     <context:component-scan base-package="edu.gx.web">  
  15.         <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>  
  16.     </context:component-scan>  
  17.     <!-- 日期转换  必须放在<mvc:annotation-driven />前面 -->  
  18.     <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"></bean>  
  19.     <mvc:annotation-driven />  
  20.     <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->    
  21.     <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>  
  22.     <!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->    
  23.     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" >    
  24.         <property name="prefix" value="/WEB-INF/jsp"></property>    
  25.         <property name="suffix" value=".jsp"></property>    
  26.     </bean>    
  27. </beans>  

再有spring-dubbo-customer.xml配置:

[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  4.     xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"  
  5.     xsi:schemaLocation="http://www.springframework.org/schema/beans            
  6.     http://www.springframework.org/schema/beans/spring-beans.xsd            
  7.     http://code.alibabatech.com/schema/dubbo            
  8.     http://code.alibabatech.com/schema/dubbo/dubbo.xsd">  
  9.     <dubbo:application name="dubbo-service-client" />  
  10.    <!--  zookeeper安装所在服务器IP地址,本机是127.0.0.1 -->  
  11.     <dubbo:registry address="zookeeper://192.168.3.16:2181" />  
  12.     <!-- 可以有多个Service -->  
  13.     <dubbo:reference id="userService" interface="end.gx.service.UserService"  check="false"  timeout="10000" retries="0"/>  
  14. </beans>  

最后web.xml配置:

[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.     xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"  
  4.     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"  
  5.     id="WebApp_ID" version="2.5">  
  6.   
  7.     <context-param>  
  8.         <param-name>contextConfigLocation</param-name>  
  9.         <param-value>  
  10.             classpath:spring-dubbo-customer.xml  
  11.         </param-value>  
  12.     </context-param>  
  13.   
  14.     <listener>  
  15.         <description>spring监听器</description>  
  16.         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  17.     </listener>  
  18.   
  19.     <filter>  
  20.         <filter-name>characterEncodingFilter</filter-name>  
  21.         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>  
  22.         <init-param>  
  23.             <param-name>encoding</param-name>  
  24.             <param-value>UTF-8</param-value>  
  25.         </init-param>  
  26.         <init-param>  
  27.             <param-name>forceEncoding</param-name>  
  28.             <param-value>true</param-value>  
  29.         </init-param>  
  30.     </filter>  
  31.     <filter-mapping>  
  32.         <filter-name>characterEncodingFilter</filter-name>  
  33.         <url-pattern>/*</url-pattern>  
  34.     </filter-mapping>  
  35.     
  36.   <servlet>  
  37.         <description>spring mvc servlet</description>  
  38.         <servlet-name>springMvc</servlet-name>  
  39.         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
  40.         <init-param>  
  41.             <description>spring mvc 配置文件</description>  
  42.             <param-name>contextConfigLocation</param-name>  
  43.             <param-value>classpath:spring-mvc.xml</param-value>  
  44.         </init-param>  
  45.         <init-param>  
  46.             <param-name>activeReverseAjaxEnabled</param-name>  
  47.             <param-value>true</param-value>  
  48.         </init-param>  
  49.         <load-on-startup>1</load-on-startup>  
  50.     </servlet>  
  51.     <servlet-mapping>  
  52.         <servlet-name>springMvc</servlet-name>  
  53.         <url-pattern>*.do</url-pattern>  
  54.     </servlet-mapping>  
  55. </web-app>  

简单的分别式架构搭建完成,接下来就是将提供者(service)运行成功,接着将service打包成war包,放在tomcat下运行。在运行service的前提是zookeeper要运行。这样service服务才能正常注册到zk服务中心。

接着在Eclipse运行消费方(web),当界面能把数据查询出来,证明分布式架构才是完全搭建成功。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值