dubbo 使用 学习四(springmvc+spring+dubbo+zookeeper本地伪集群)

通过之前的两篇我们能在本地搭建单一和集群两种方式的dubbo服务,这篇我们来看 springmvc+spring+mybatis+dubbo+zookeeper 的项目的搭建……

不管是什么样的项目中使用dubbo 和zookeeper做分布式的服务,我们要做的就是将服务提供者注册到zookeeper中而服务消费者来消费服务提供者提供的服务,所以我们要做的就是安装zookeeper 和服务注册到zookeeper中,服务消费者从zookeeper中获取服务提供者的信息获取并消费服务,废话少说下面我们来看看代码……

我这个demo配置的是单个的所以安装zookeeper之后只需要修改DataDir 的路径其他的都不用修改而且安装也很简单所以这里就不啰嗦了,自己找度娘……

一、服务提供者

1、整体目录结构:

通过这个目录结构我们看到的就是一个平时的web项目……

2、这里需要的jar包除了平时springmvc+sping+mybatis 的jar包还有zookeeper 和dubbo的相关jar包,下面看看pom.xml 配置文件

这里说明一下,这样配置后有一个springjar包冲突,是哪个冲突了是不是不好找,其实也不是,你先把dubbo zookeeper的配置去了,看看有哪些jar包在加上看看多的那个spring 直接删除就可以……


[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>com.test</groupId>  
  6.   <artifactId>dubboser3</artifactId>  
  7.   <version>0.0.1-SNAPSHOT</version>  
  8.   <packaging>jar</packaging>  
  9.   
  10.   <name>dubboser3</name>  
  11.   <url>http://maven.apache.org</url>  
  12.   
  13.   <properties>  
  14.     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
  15.   </properties>  
  16.   
  17. <!-- 项目所依赖的jar包 -->  
  18.     <dependencies>  
  19.     <!-- spring springmvc -->  
  20.         <dependency>  
  21.             <groupId>org.springframework</groupId>  
  22.             <artifactId>spring-core</artifactId>  
  23.             <version>4.2.0.RELEASE</version>  
  24.         </dependency>  
  25.         <dependency>  
  26.             <groupId>org.springframework</groupId>  
  27.             <artifactId>spring-webmvc</artifactId>  
  28.             <version>4.2.0.RELEASE</version>  
  29.         </dependency>  
  30.         <dependency>  
  31.             <groupId>org.springframework</groupId>  
  32.             <artifactId>spring-tx</artifactId>  
  33.             <version>4.2.0.RELEASE</version>  
  34.         </dependency>  
  35.         <dependency>  
  36.             <groupId>org.springframework</groupId>  
  37.             <artifactId>spring-jdbc</artifactId>  
  38.             <version>4.2.0.RELEASE</version>  
  39.         </dependency>  
  40.         <dependency>  
  41.             <groupId>org.springframework</groupId>  
  42.             <artifactId>spring-test</artifactId>  
  43.             <version>4.2.0.RELEASE</version>  
  44.         </dependency>  
  45.         <dependency>  
  46.             <groupId>org.aspectj</groupId>  
  47.             <artifactId>aspectjweaver</artifactId>  
  48.             <version>1.8.6</version>  
  49.         </dependency>  
  50.         <!-- mybatis -->  
  51.         <dependency>  
  52.             <groupId>org.mybatis</groupId>  
  53.             <artifactId>mybatis</artifactId>  
  54.             <version>3.3.0</version>  
  55.         </dependency>  
  56.         <!-- mybatis 链接spring包 -->  
  57.         <dependency>  
  58.             <groupId>org.mybatis</groupId>  
  59.             <artifactId>mybatis-spring</artifactId>  
  60.             <version>1.2.3</version>  
  61.         </dependency>  
  62.         <!-- mysql 驱动 -->  
  63.         <dependency>  
  64.             <groupId>mysql</groupId>  
  65.             <artifactId>mysql-connector-java</artifactId>  
  66.             <version>5.1.36</version>  
  67.         </dependency>  
  68.         <!--druid数据库连接池  -->  
  69.         <dependency>  
  70.             <groupId>com.alibaba</groupId>  
  71.             <artifactId>druid</artifactId>  
  72.             <version>1.0.15</version>  
  73.         </dependency>  
  74.         <dependency>  
  75.             <groupId>org.codehaus.jackson</groupId>  
  76.             <artifactId>jackson-mapper-asl</artifactId>  
  77.             <version>1.9.12</version>  
  78.         </dependency>  
  79.         <!--文件上传  -->  
  80.         <dependency>  
  81.             <groupId>commons-fileupload</groupId>  
  82.             <artifactId>commons-fileupload</artifactId>  
  83.             <version>1.3.1</version>  
  84.         </dependency>  
  85.         <!-- servlet -->  
  86.         <dependency>  
  87.             <groupId>javax.servlet</groupId>  
  88.             <artifactId>javax.servlet-api</artifactId>  
  89.             <version>3.1.0</version>  
  90.         </dependency>  
  91.         <!--jackson-->  
  92.         <dependency>  
  93.             <groupId>com.fasterxml.jackson.core</groupId>  
  94.             <artifactId>jackson-core</artifactId>  
  95.             <version>2.6.1</version>  
  96.         </dependency>  
  97.         <dependency>  
  98.             <groupId>com.fasterxml.jackson.core</groupId>  
  99.             <artifactId>jackson-databind</artifactId>  
  100.             <version>2.6.1</version>  
  101.         </dependency>  
  102.         <!--json -->  
  103.         <dependency>  
  104.             <groupId>net.sf.json-lib</groupId>  
  105.             <artifactId>json-lib</artifactId>  
  106.             <version>2.4</version>  
  107.             <classifier>jdk15</classifier>  
  108.         </dependency>  
  109.   
  110.         <!--log -->  
  111.         <dependency>  
  112.             <groupId>org.slf4j</groupId>  
  113.             <artifactId>slf4j-log4j12</artifactId>  
  114.             <version>1.7.2</version>  
  115.         </dependency>  
  116.         <!-- jsp c标签引入 -->  
  117.         <dependency>  
  118.             <groupId>org.apache.taglibs</groupId>  
  119.             <artifactId>taglibs-standard-spec</artifactId>  
  120.             <version>1.2.1</version>  
  121.         </dependency>  
  122.         <dependency>  
  123.             <groupId>org.apache.taglibs</groupId>  
  124.             <artifactId>taglibs-standard-impl</artifactId>  
  125.             <version>1.2.1</version>  
  126.         </dependency>  
  127.   
  128.         <!--AES MD5加密编码 -->  
  129.         <dependency>  
  130.             <groupId>commons-codec</groupId>  
  131.             <artifactId>commons-codec</artifactId>  
  132.             <version>1.4</version>  
  133.         </dependency>  
  134.         <!-- httpclient -->  
  135.          <dependency>  
  136.             <groupId>commons-logging</groupId>  
  137.             <artifactId>commons-logging</artifactId>  
  138.             <version>1.1.1</version>  
  139.         </dependency>  
  140.           <dependency>  
  141.             <groupId>commons-httpclient</groupId>  
  142.             <artifactId>commons-httpclient</artifactId>  
  143.             <version>3.0.1</version>  
  144.         </dependency>  
  145.           
  146.         <!--测试 -->  
  147.         <dependency>  
  148.             <groupId>junit</groupId>  
  149.             <artifactId>junit</artifactId>  
  150.             <version>4.12</version>  
  151.             <scope>test</scope>  
  152.         </dependency>  
  153.           
  154.         <!-- dubbo -->  
  155.     <dependency>  
  156.       <groupId>com.alibaba</groupId>  
  157.       <artifactId>dubbo</artifactId>  
  158.       <version>2.5.3</version>  
  159.     </dependency>  
  160.     <!-- zkclient  -->  
  161.     <dependency>  
  162.       <groupId>com.github.sgroschupf</groupId>  
  163.       <artifactId>zkclient</artifactId>  
  164.       <version>0.1</version>  
  165.     </dependency>  
  166.     <!--  zookeeper -->  
  167.     <dependency>  
  168.       <groupId>org.apache.zookeeper</groupId>  
  169.       <artifactId>zookeeper</artifactId>  
  170.       <version>3.4.5</version>  
  171.     </dependency>  
  172.           
  173.     </dependencies>  
  174.     <!-- 构建项目所需要的信息 -->  
  175.     <build>  
  176.     <plugins>  
  177.         <plugin>  
  178.             <groupId>org.apache.maven.plugins</groupId>  
  179.             <artifactId>maven-war-plugin</artifactId>  
  180.             <version>2.1.1</version>  
  181.             <configuration>  
  182.                 <!--指定web.xml的路径 -->  
  183.                 <webXml>WebRoot\WEB-INF\web.xml</webXml>  
  184.                 <!--指定jsp、js、css的路劲 -->  
  185.                 <warSourceDirectory>WebRoot</warSourceDirectory>  
  186.             </configuration>  
  187.         </plugin>  
  188.         <plugin>  
  189.             <groupId>org.apache.maven.plugins</groupId>  
  190.             <artifactId>maven-compiler-plugin</artifactId>  
  191.             <configuration>  
  192.                 <source>1.7</source>  
  193.                 <target>1.7</target>  
  194.             </configuration>  
  195.         </plugin>  
  196.     </plugins>  
  197. </build>  
  198. </project>  

3、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" 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_3_0.xsd" id="WebApp_ID" version="3.0">  
  3.   <display-name>dubbocli3</display-name>  
  4.   <listener>  
  5.     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  6.   </listener>  
  7.   <!-- log4j -->  
  8.     <listener>  
  9.         <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>  
  10.     </listener>  
  11.   <context-param>  
  12.     <param-name>contextConfigLocation</param-name>  
  13.     <param-value>    
  14.          classpath:config/springmvc-servlet.xml,    
  15.          classpath:config/ApplicationContext.xml    
  16.        </param-value>  
  17.   </context-param>  
  18.   <!-- log4j -->  
  19.     <context-param>  
  20.         <param-name>log4jConfigLocation</param-name>  
  21.         <param-value>  
  22.          classpath:log4j.properties  
  23.          </param-value>  
  24.     </context-param>  
  25.     
  26.   <filter>  
  27.     <filter-name>encodingFilter</filter-name>  
  28.     <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>  
  29.     <init-param>  
  30.       <param-name>encoding</param-name>  
  31.       <param-value>utf-8</param-value>  
  32.     </init-param>  
  33.     <init-param>  
  34.       <param-name>forceEncoding</param-name>  
  35.       <param-value>true</param-value>  
  36.     </init-param>  
  37.   </filter>  
  38.   <filter-mapping>  
  39.     <filter-name>encodingFilter</filter-name>  
  40.     <url-pattern>*.do</url-pattern>  
  41.   </filter-mapping>  
  42.   <servlet>  
  43.     <servlet-name>springmvc</servlet-name>  
  44.     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
  45.     <init-param>  
  46.       <param-name>contextConfigLocation</param-name>  
  47.       <param-value>classpath:config/springmvc-servlet.xml</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.   <servlet>  
  56.     <servlet-name>DruidStatView</servlet-name>  
  57.     <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>  
  58.   </servlet>  
  59.   <servlet-mapping>  
  60.     <servlet-name>DruidStatView</servlet-name>  
  61.     <url-pattern>/druid/*</url-pattern>  
  62.   </servlet-mapping>  
  63.   <filter>  
  64.     <filter-name>DruidWebStatFilter</filter-name>  
  65.     <filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class>  
  66.     <init-param>  
  67.       <param-name>exclusions</param-name>  
  68.       <param-value>weburi.json,.html,.js,.gif,.jpg,.png,.css,.ico,/druid/*</param-value>  
  69.     </init-param>  
  70.     <init-param>  
  71.       <param-name>sessionStatMaxCount</param-name>  
  72.       <param-value>10</param-value>  
  73.     </init-param>  
  74.     <init-param>  
  75.       <param-name>principalSessionName</param-name>  
  76.       <param-value>FRONT_USER</param-value>  
  77.     </init-param>  
  78.   </filter>  
  79.   <filter-mapping>  
  80.     <filter-name>DruidWebStatFilter</filter-name>  
  81.     <url-pattern>*.do</url-pattern>  
  82.   </filter-mapping>  
  83.   <filter-mapping>  
  84.     <filter-name>DruidWebStatFilter</filter-name>  
  85.     <url-pattern>*.jsp</url-pattern>  
  86.   </filter-mapping>  
  87.   <welcome-file-list>  
  88.     <welcome-file>index.html</welcome-file>  
  89.     <welcome-file>index.htm</welcome-file>  
  90.     <welcome-file>index.jsp</welcome-file>  
  91.     <welcome-file>default.html</welcome-file>  
  92.   </welcome-file-list>  
  93. </web-app>  

云服务

子系统:后台管理系统、Restfu服务系统、Dubbo服务/管控/监控中心

Zookeeper注册中心、报表分析系统、日志记录系统、定时调度系统

搜索引擎系统、分布式文件系统、消息系统、SSO单点登录系统

SOA管控平台、UI组件系统、OA办公系统、CMS新闻发布系统

支付系统、数据库配置系统、工作流系统、云服务平台

strip


愿意了解框架技术或者源码的朋友直接求求交流分享技术:2042849237
分布式的一些解决方案,有愿意了解的朋友可以找我们团队探讨
更多详细源码参考来源:http://minglisoft.cn/technology


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31452580/viewspace-2147020/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/31452580/viewspace-2147020/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值