当前位置:   article > 正文

测试Zookper注册中心_注册中心 测试 生产

注册中心 测试 生产

之前已经安装完zookper,现在写两个测试工程,来测试zookper是否管用(疑问?dubbox不是有监控控制台?--以后会讲到)

首先建立qianjiian-provider(maven 工程)

添加

 添加pom依赖

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  2. <modelVersion>4.0.0</modelVersion>
  3. <groupId>com.unistec</groupId>
  4. <artifactId>qianjibian-provider</artifactId>
  5. <version>0.0.1-SNAPSHOT</version>
  6. <packaging>war</packaging>
  7. <properties>
  8. <spring.version>4.2.4.RELEASE</spring.version>
  9. </properties>
  10. <dependencies>
  11. <!-- Spring -->
  12. <dependency>
  13. <groupId>org.springframework</groupId>
  14. <artifactId>spring-context</artifactId>
  15. <version>${spring.version}</version>
  16. </dependency>
  17. <dependency>
  18. <groupId>org.springframework</groupId>
  19. <artifactId>spring-beans</artifactId>
  20. <version>${spring.version}</version>
  21. </dependency>
  22. <dependency>
  23. <groupId>org.springframework</groupId>
  24. <artifactId>spring-webmvc</artifactId>
  25. <version>${spring.version}</version>
  26. </dependency>
  27. <dependency>
  28. <groupId>org.springframework</groupId>
  29. <artifactId>spring-jdbc</artifactId>
  30. <version>${spring.version}</version>
  31. </dependency>
  32. <dependency>
  33. <groupId>org.springframework</groupId>
  34. <artifactId>spring-aspects</artifactId>
  35. <version>${spring.version}</version>
  36. </dependency>
  37. <dependency>
  38. <groupId>org.springframework</groupId>
  39. <artifactId>spring-jms</artifactId>
  40. <version>${spring.version}</version>
  41. </dependency>
  42. <dependency>
  43. <groupId>org.springframework</groupId>
  44. <artifactId>spring-context-support</artifactId>
  45. <version>${spring.version}</version>
  46. </dependency>
  47. <!-- dubbo相关 -->
  48. <dependency>
  49. <groupId>com.alibaba</groupId>
  50. <artifactId>dubbo</artifactId>
  51. <version>2.8.4</version>
  52. </dependency>
  53. <dependency>
  54. <groupId>org.apache.zookeeper</groupId>
  55. <artifactId>zookeeper</artifactId>
  56. <version>3.4.6</version>
  57. </dependency>
  58. <dependency>
  59. <groupId>com.github.sgroschupf</groupId>
  60. <artifactId>zkclient</artifactId>
  61. <version>0.1</version>
  62. </dependency>
  63. <dependency>
  64. <groupId>javassist</groupId>
  65. <artifactId>javassist</artifactId>
  66. <version>3.11.0.GA</version>
  67. </dependency>
  68. </dependencies>
  69. <build>
  70. <plugins>
  71. <plugin>
  72. <groupId>org.apache.maven.plugins</groupId>
  73. <artifactId>maven-compiler-plugin</artifactId>
  74. <version>2.3.2</version>
  75. <configuration>
  76. <source>1.7</source>
  77. <target>1.7</target>
  78. </configuration>
  79. </plugin>
  80. <plugin>
  81. <groupId>org.apache.tomcat.maven</groupId>
  82. <artifactId>tomcat7-maven-plugin</artifactId>
  83. <configuration>
  84. <!-- 指定端口 -->
  85. <port>8081</port>
  86. <!-- 请求路径 -->
  87. <path>/</path>
  88. </configuration>
  89. </plugin>
  90. </plugins>
  91. </build>
  92. <!-- <build>
  93. <plugins>
  94. <plugin>
  95. <groupId>org.apache.maven.plugins</groupId>
  96. <artifactId>maven-compiler-plugin</artifactId>
  97. <version>2.7</version>
  98. <configuration>
  99. <encoding>UTF-8</encoding>
  100. </configuration>
  101. <configuration>
  102. <source>1.8</source>
  103. <target>1.8</target>
  104. </configuration>
  105. </plugin>
  106. <plugin>
  107. <groupId>org.apache.maven.plugins</groupId>
  108. <artifactId>maven-compiler-plugin</artifactId>
  109. <version>3.2</version>
  110. <configuration>
  111. <source>1.8</source>
  112. <target>1.8</target>
  113. <encoding>UTF-8</encoding>
  114. </configuration>
  115. </plugin>
  116. <plugin>
  117. <groupId>org.apache.tomcat.maven</groupId>
  118. <artifactId>tomcat7-maven-plugin</artifactId>
  119. <version>2.2</version>
  120. <configuration>
  121. 指定端口
  122. <port>8081</port>
  123. 请求路径
  124. <path>/</path>
  125. </configuration>
  126. </plugin>
  127. </plugins>
  128. </build> -->
  129. </project>

注意:springmvc用的版本未4.2.4,支持的JDK环境为1.7(没有环境?1:安装1.7,eclipse中更换编译环境  2:升级Springmvc版本4.2以上)

添加web.xml文件

  1. <!-- 加载spring容器 -->
  2. <context-param>
  3. <param-name>contextConfigLocation</param-name>
  4. <param-value>classpath:applicationContext*.xml</param-value>
  5. </context-param>
  6. <listener>
  7. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  8. </listener>

 定义一个用户接口

  1. public interface UserService {
  2. public String getName();
  3. }

 添加实现类

  1. @Service
  2. public class UserServiceImpl implements UserService {
  3. public String getName() {
  4. return "测试";
  5. }
  6. }

注意:service注解不是spring下的注解,是com.alibaba.dubbo.config.annotation.Service

配置applicationContext-service.xml

  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" xmlns:p="http://www.springframework.org/schema/p"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:mvc="http://www.springframework.org/schema/mvc"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  7. http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
  8. http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
  9. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
  10. <dubbo:application name="qianjibian-provider"/>
  11. <dubbo:registry address="zookeeper://192.168.25.129:2181"/>
  12. <dubbo:annotation package="com.unistec.service" />
  13. </beans>

启动tomcat测试,命令tomcat7:run

至此服务提供者完成

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/851630
推荐阅读
相关标签
  

闽ICP备14008679号