• dubbo简单入门使用


    创建Service层

    <properties>

           <spring.version>4.2.5.RELEASE</spring.version>

        </properties>

     

      <dependencies>

           <!-- Spring -->

           <dependency>

               <groupId>org.springframework</groupId>

               <artifactId>spring-context</artifactId>

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

           </dependency>

     

           <dependency>

               <groupId>org.springframework</groupId>

               <artifactId>spring-beans</artifactId>

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

           </dependency>

     

           <dependency>

               <groupId>org.springframework</groupId>

               <artifactId>spring-webmvc</artifactId>

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

           </dependency>

     

           <dependency>

               <groupId>org.springframework</groupId>

               <artifactId>spring-jdbc</artifactId>

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

           </dependency>

     

           <dependency>

               <groupId>org.springframework</groupId>

               <artifactId>spring-aspects</artifactId>

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

           </dependency>

     

           <dependency>

               <groupId>org.springframework</groupId>

               <artifactId>spring-jms</artifactId>

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

           </dependency>

     

           <dependency>

               <groupId>org.springframework</groupId>

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

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

           </dependency>

     

           <!-- dubbo -->

           <dependency>

               <groupId>com.alibaba</groupId>

               <artifactId>dubbo</artifactId>

               <version>2.5.3</version>

           </dependency>

           <dependency>

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

               <artifactId>zookeeper</artifactId>

               <version>3.3.3</version>

           </dependency>

           <dependency>

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

               <artifactId>zkClient</artifactId>

               <version>0.1</version>

           </dependency>

           <dependency>

               <groupId>javassist</groupId>

               <artifactId>javassist</artifactId>

               <version>3.11.0.GA</version>

           </dependency>

          

          

           <dependency> 

                <groupId>log4j</groupId> 

                <artifactId>log4j</artifactId> 

                <version>1.2.15</version> 

                <exclusions> 

                    <exclusion> 

                        <groupId>javax.jms</groupId> 

                        <artifactId>jms</artifactId> 

                    </exclusion> 

                    <exclusion> 

                        <groupId>com.sun.jdmk</groupId> 

                        <artifactId>jmxtools</artifactId> 

                    </exclusion> 

                    <exclusion> 

                        <groupId>com.sun.jmx</groupId> 

                        <artifactId>jmxri</artifactId> 

                    </exclusion> 

                </exclusions> 

            </dependency> 

     

     

        </dependencies>

     

        <build>

           <plugins>

               <plugin>

                  <groupId>org.apache.maven.plugins</groupId>

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

                  <version>2.3.2</version>

                  <configuration>

                      <source>1.7</source>

                      <target>1.7</target>

                  </configuration>

               </plugin>

               <plugin>

                  <groupId>org.apache.tomcat.maven</groupId>

                  <artifactId>tomcat7-maven-plugin</artifactId>

                  <version>2.1</version>

                  <configuration>

                      <port>8081</port>

                      <path>/</path>

                      <uriEncoding>UTF-8</uriEncoding>

                  </configuration>

               </plugin>

     

           </plugins>

        </build>

       

     

     

     

    接口

     

     

    实现类

     

     

     

     

     

     

     

     

    配置文件spring

     

     

    创建Web层

     

    <properties>

           <spring.version>4.2.5.RELEASE</spring.version>

        </properties>

     

      <dependencies>

           <!-- Spring -->

           <dependency>

               <groupId>org.springframework</groupId>

               <artifactId>spring-context</artifactId>

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

           </dependency>

     

           <dependency>

               <groupId>org.springframework</groupId>

               <artifactId>spring-beans</artifactId>

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

           </dependency>

     

           <dependency>

               <groupId>org.springframework</groupId>

               <artifactId>spring-webmvc</artifactId>

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

           </dependency>

     

           <dependency>

               <groupId>org.springframework</groupId>

               <artifactId>spring-jdbc</artifactId>

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

           </dependency>

     

           <dependency>

               <groupId>org.springframework</groupId>

               <artifactId>spring-aspects</artifactId>

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

           </dependency>

     

           <dependency>

               <groupId>org.springframework</groupId>

               <artifactId>spring-jms</artifactId>

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

           </dependency>

     

           <dependency>

               <groupId>org.springframework</groupId>

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

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

           </dependency>

     

           <!-- dubbo -->

           <dependency>

               <groupId>com.alibaba</groupId>

               <artifactId>dubbo</artifactId>

               <version>2.5.3</version>

           </dependency>

           <dependency>

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

               <artifactId>zookeeper</artifactId>

               <version>3.3.3</version>

           </dependency>

           <dependency>

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

               <artifactId>zkClient</artifactId>

               <version>0.1</version>

           </dependency>

           <dependency>

               <groupId>javassist</groupId>

               <artifactId>javassist</artifactId>

               <version>3.11.0.GA</version>

           </dependency>

          

          

           <dependency> 

                <groupId>log4j</groupId> 

                <artifactId>log4j</artifactId> 

                <version>1.2.15</version> 

                <exclusions> 

                    <exclusion> 

                        <groupId>javax.jms</groupId> 

                        <artifactId>jms</artifactId> 

                    </exclusion> 

                    <exclusion> 

                        <groupId>com.sun.jdmk</groupId> 

                        <artifactId>jmxtools</artifactId> 

                    </exclusion> 

                    <exclusion> 

                        <groupId>com.sun.jmx</groupId> 

                        <artifactId>jmxri</artifactId> 

                    </exclusion> 

                </exclusions> 

            </dependency> 

     

     

        </dependencies>

     

        <build>

           <plugins>

               <plugin>

                  <groupId>org.apache.maven.plugins</groupId>

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

                  <version>2.3.2</version>

                  <configuration>

                      <source>1.7</source>

                      <target>1.7</target>

                  </configuration>

               </plugin>

               <plugin>

                  <groupId>org.apache.tomcat.maven</groupId>

                  <artifactId>tomcat7-maven-plugin</artifactId>

                  <version>2.1</version>

                  <configuration>

                      <port>8088</port>

                      <path>/</path>

                      <uriEncoding>UTF-8</uriEncoding>

                  </configuration>

               </plugin>

     

           </plugins>

        </build>

     

    接口

     

    Controller

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

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

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

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

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

        xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"

        xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd

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

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

            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd

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

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

     

        <mvc:annotation-driven>

            <mvc:message-converters register-defaults="false">

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

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

                </bean>

            </mvc:message-converters>

        </mvc:annotation-driven>

       

       

        <!-- 当前应用名称 -->

        <dubbo:application name="mydubbo-web" />

        <!-- 注册中心地址 -->

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

        <!-- 注解 包扫描 -->

        <dubbo:annotation package="com.cxl.demo.controller" />

     

     

    </beans>

     

     

     

    Web.xml

    <context-param>

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

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

       </context-param>

     

       <listener>

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

       </listener>

     

     

    配置Zookeeper

    下载地址https://www.apache.org/dyn/closer.cgi/zookeeper/

     

    修改后缀名

     

    启动bin目录下的cmd

    这里注意,启动zkServer的时候要用cmd启动

     

    再启动zkCli

    发送请求

  • 相关阅读:
    [置顶] NO.4 使用预处理器进行调试
    VC用OLE方式读写Excel
    Eclipse 4.2 + Tomcat 7.x + JDK 7 搭建Java Web开发环境
    (step4.3.1) hdu 1010(Tempter of the Bone——DFS)
    linked-list-random-node
    insert-delete-getrandom-o1-duplicates-allowed
    C++中对Mysql的操作函数可以参考以下blog中的内容
    insert-delete-getrandom-o1
    kth-smallest-element-in-a-sorted-matrix
    combination-sum-iv
  • 原文地址:https://www.cnblogs.com/chengxiaolong/p/10206337.html
Copyright © 2020-2023  润新知