SSM整合Dubbo

一.新增maven项目,命名为Days61DubboSSM

该父项目为最高父项目

1.在父项目中添加依赖管理以及jdk插件

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.qfedu</groupId>
    <artifactId>Days61DubboSSM</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>DubboPojo</module>
        <module>DubboDao</module>
        <module>DubboServiceContent</module>
        <module>DubboPortal</module>
    </modules>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-webmvc</artifactId>
                <version>4.3.6.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis</artifactId>
                <version>3.4.4</version>
            </dependency>
            <dependency>
                <groupId>org.aspectj</groupId>
                <artifactId>
                    com.springsource.org.aspectj.weaver
                </artifactId>
                <version>1.6.8.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid</artifactId>
                <version>1.0.28</version>
            </dependency>
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.44</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>2.8.6</version>
            </dependency>
            <dependency>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis-spring</artifactId>
                <version>1.3.1</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-tx</artifactId>
                <version>4.3.6.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-jdbc</artifactId>
                <version>4.3.6.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>dubbo</artifactId>
                <version>2.5.3</version>
                <!-- 剔除dubbo中比较低版本的spring依赖 -->
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.apache.zookeeper</groupId>
                <artifactId>zookeeper</artifactId>
                <version>3.4.6</version>
                <type>pom</type>
            </dependency>
            <dependency>
                <groupId>com.101tec</groupId>
                <artifactId>zkclient</artifactId>
                <version>0.7</version>
            </dependency>
            <dependency>
                <groupId>commons-io</groupId>
                <artifactId>commons-io</artifactId>
                <version>2.4</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <!-- define the project compile level -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

二.在父项目中添加子模块DubboPojo

1.修改pom文件,添加lombok依赖

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <parent>
        <artifactId>Days61DubboSSM</artifactId>
        <groupId>com.qfedu</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>DubboPojo</artifactId>

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.18</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
</project>

2.新增pojo类,并且让该类实现序列化接口

package com.qfedu.pojo;

import lombok.Data;

import java.io.Serializable;

@Data
public class User implements Serializable {
    private String userId;
    private String username;
    private String password;
    private String email;
    private String tel;
    private int level;
    private int integral;
    private int ifNew;
}

三. 在父项目中添加子模块DubboDao

1.修改pom文件,Dao模块依赖于Pojo模块

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <parent>
        <artifactId>Days61DubboSSM</artifactId>
        <groupId>com.qfedu</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>DubboDao</artifactId>

    <dependencies>
        <dependency>
            <groupId>com.qfedu</groupId>
            <artifactId>DubboPojo</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>
                com.springsource.org.aspectj.weaver
            </artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
        </dependency>
    </dependencies>
</project>

2.在src中添加Dao接口的java代码

package com.qfedu.dao;

import com.qfedu.pojo.User;

import java.util.List;

public interface IUserDao {

    List<User> getAllUsers();
}

3.在resources中添加dao接口对应的mapper的xml映射文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- 整个映射文件为mapper节点,里面包含namespace属性 -->
   <mapper namespace="com.qfedu.dao.IUserDao">
   
   <select id="getAllUsers" resultType="user">
      select user_id userId, user_name username, password, email, tel, level, integral, if_new ifNew from users
   </select>
</mapper>

四.在父项目中添加子模块DubboServiceContent

1.在当前模块中新增模块DubboServiceContentInterface

(1)新增接口

package com.qfedu.service;

import com.qfedu.pojo.User;

import java.util.List;

public interface IUserService {

    List<User> getAllUsers();
}

(2)pom文件

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <parent>
        <artifactId>DubboServiceContent</artifactId>
        <groupId>com.qfedu</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>DubboServiceContentInterface</artifactId>
</project>

2.在当前模块中新增模块DubboServiceContentProvider

(1)新增接口对应的实现类UserServiceImpl

package com.qfedu.service.impl;

import com.qfedu.dao.IUserDao;
import com.qfedu.pojo.User;
import com.qfedu.service.IUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements IUserService {

    @Resource
    private IUserDao userDao;

    @Override
    public List<User> getAllUsers() {
        return userDao.getAllUsers();
    }
}

(2)修改pom文件,该提供者依赖于接口,再添加tomcat的插件来运行该子模块

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <parent>
        <artifactId>DubboServiceContent</artifactId>
        <groupId>com.qfedu</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <packaging>war</packaging>

    <artifactId>DubboServiceContentProvider</artifactId>

    <dependencies>
        <dependency>
            <groupId>com.qfedu</groupId>
            <artifactId>DubboServiceContentInterface</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>com.springsource.org.aspectj.weaver</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>com.101tec</groupId>
            <artifactId>zkclient</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
        </dependency>
    </dependencies>

    <build>
        <!--不过滤java下的xml文件-->
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
        <plugins>
            <!-- 添加tomcat插件 -->
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <path>/</path>
                    <port>8081</port>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

(3)在resources下新增db.properties文件

aaa=root
bbb=*****
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3307/supermarket?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8

maxActive=20

(4)在resources下新增spring-mybatis.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:context="http://www.springframework.org/schema/context"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xsi:schemaLocation="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.3.xsd
      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
   
   <context:property-placeholder location="classpath:db.properties"/>
   
   <bean class="com.alibaba.druid.pool.DruidDataSource" id="ds">
      <property name="url" value="${url}"></property>
      <property name="username" value="${aaa}"></property>
      <property name="password" value="${bbb}"></property>
      <property name="driverClassName" value="${driver}"></property>
      
      <property name="maxActive" value="${maxActive}"></property>
   </bean>
   
   <bean class="org.mybatis.spring.SqlSessionFactoryBean" id="sf">
      <property name="typeAliasesPackage" value="com.qfedu.pojo" />
      <property name="mapperLocations" value="classpath:com/qfedu/dao/*.xml" />
      <property name="dataSource" ref="ds"></property>
      <property name="configLocation" value="classpath:mybatis-config.xml" />
   </bean>
   
   <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
      <property name="basePackage" value="com.qfedu.dao" />
      <property name="sqlSessionFactoryBeanName" value="sf"></property>
   </bean>
   
   <bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager" id="dtx">
      <property name="dataSource" ref="ds"></property>
   </bean>
   
   <tx:advice id="tx" transaction-manager="dtx">
      <!--定义属性,声明事务规则 -->
      <tx:attributes>
         <tx:method name="create*" propagation="REQUIRED" isolation="DEFAULT"
            rollback-for="Exception" />
         <tx:method name="insert*" propagation="REQUIRED" isolation="DEFAULT"
            rollback-for="Exception" />
         <tx:method name="add*" propagation="REQUIRED" isolation="DEFAULT"
            rollback-for="Exception" />
         <tx:method name="upd*" propagation="REQUIRED" isolation="DEFAULT"
            rollback-for="Exception" />
         <tx:method name="del*" propagation="REQUIRED" isolation="DEFAULT"
            rollback-for="Exception" />
         <tx:method name="execute*" propagation="REQUIRED"
            isolation="DEFAULT" rollback-for="Exception" />
         <tx:method name="do*" propagation="REQUIRED" isolation="DEFAULT"
            rollback-for="Exception" />
         <tx:method name="save*" propagation="REQUIRED" isolation="DEFAULT"
            rollback-for="Exception" />
         <tx:method name="set*" propagation="REQUIRED" isolation="DEFAULT"
            rollback-for="Exception" />
         <tx:method name="get*" propagation="SUPPORTS" isolation="DEFAULT"
            read-only="true" />
         <tx:method name="show*" propagation="SUPPORTS" isolation="DEFAULT"
            read-only="true" />
         <tx:method name="list*" propagation="SUPPORTS" isolation="DEFAULT"
            read-only="true" />
         <tx:method name="select*" propagation="SUPPORTS" isolation="DEFAULT"
            read-only="true" />
         <tx:method name="query*" propagation="SUPPORTS" isolation="DEFAULT"
            read-only="true" />
         <tx:method name="has*" propagation="SUPPORTS" isolation="DEFAULT"
            read-only="true" />
         <tx:method name="ntx*" propagation="NOT_SUPPORTED" />
         <tx:method name="*" propagation="SUPPORTS" isolation="DEFAULT"
            read-only="true" />
      </tx:attributes>
   </tx:advice>
   
   <aop:config>
      <aop:pointcut expression="execution(* com.qfedu.service.*.*(..))" id="mpc"/>
      <aop:advisor advice-ref="tx" pointcut-ref="mpc" />
   </aop:config>
</beans>

(5)在resources下新增mybatis-config.xml文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
  PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
  
  <settings>
   <setting name="logImpl" value="STDOUT_LOGGING"/>
  </settings>
</configuration>

(6)在resources下新增spring-dubbo.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"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="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.3.xsd
      http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
   <context:component-scan base-package="com.qfedu.service" />
   
   <!-- 定义服务提供者在dubbo中的名称 -->
   <dubbo:application name="DubboServiceContentProvider"/>
   
   <!-- 配置dubbo协议, dubbo, RMI, hession -->
   <dubbo:protocol name="dubbo" port="20880" />
   
   <!-- 完成dubbo的注册 -->
   <!-- <dubbo:registry address="zookeeper://192.168.31.13:2181"></dubbo:registry> -->
   <dubbo:registry address="zookeeper://192.168.31.134:2181"></dubbo:registry>
   
   <!-- 将接口暴露给消费方 -->
   <dubbo:service interface="com.qfedu.service.IUserService" ref="userServiceImpl"></dubbo:service>
</beans>

(7)修改web.xml文件,来加载所有的配置文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring-*.xml</param-value>
    </context-param>

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

3.修改当前子模块的pom文件

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <parent>
        <artifactId>Days61DubboSSM</artifactId>
        <groupId>com.qfedu</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>DubboServiceContent</artifactId>
    <packaging>pom</packaging>

    <dependencies>
        <dependency>
            <groupId>com.qfedu</groupId>
            <artifactId>DubboDao</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

    <modules>
        <module>DubboServiceContentInterface</module>
        <module>DubboServiceContentProvider</module>
    </modules>

</project>

五.新增DubboPortal子模块

1.修改该模块的pom文件,分别添加依赖以及tomcat插件,当前模块依赖于接口(不能直接依赖于提供者)

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <parent>
        <artifactId>Days61DubboSSM</artifactId>
        <groupId>com.qfedu</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>DubboPortal</artifactId>
    <packaging>war</packaging>

    <dependencies>
        <dependency>
            <groupId>com.qfedu</groupId>
            <artifactId>DubboServiceContentInterface</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
        </dependency>
        <dependency>
            <groupId>com.101tec</groupId>
            <artifactId>zkclient</artifactId>
        </dependency>
    </dependencies>

    <build>
        <!--不过滤java下的xml文件-->
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
        <plugins>

            <!-- 添加tomcat插件 -->
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <path>/</path>
                    <port>80</port>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

2.新增controller类

package com.qfedu.controller;

import com.qfedu.pojo.User;
import com.qfedu.service.IUserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class UserController {

    @Resource
    private IUserService userService;

    @GetMapping("/Users")
    public List<User> getAllUsers(){
        return userService.getAllUsers();
    }
}

3.修改当前模块的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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
  <display-name>Days94SSMDubboPortal</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  
  <!-- needed for ContextLoaderListener -->
   <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:spring-*.xml</param-value>
   </context-param>

   <!-- Bootstraps the root web application context before servlet initialization -->
   <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
   </listener>
  
  <!-- The front controller of this Spring Web application, responsible for handling all application requests -->
   <servlet>
      <servlet-name>springDispatcherServlet</servlet-name>
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      <init-param>
         <param-name>contextConfigLocation</param-name>
         <param-value>classpath:springmvc.xml</param-value>
      </init-param>
      <load-on-startup>1</load-on-startup>
   </servlet>

   <!-- Map all requests to the DispatcherServlet for handling -->
   <servlet-mapping>
      <servlet-name>springDispatcherServlet</servlet-name>
      <url-pattern>/</url-pattern>
   </servlet-mapping>
</web-app>

4.在resources下添加配置文件springmvc.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:context="http://www.springframework.org/schema/context"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.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.3.xsd">

   <context:component-scan base-package="com.qfedu.controller" />
   
   <mvc:annotation-driven />
   
   <mvc:default-servlet-handler/>
</beans>

5.在resources下添加配置文件spring-dubbo.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:context="http://www.springframework.org/schema/context"
   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://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
      http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

   <dubbo:application name="DubboPortal"/>
   
   <!-- 完成dubbo的注册 -->
   <dubbo:registry address="zookeeper://192.168.31.134:2181"></dubbo:registry>
   
   <dubbo:reference interface="com.qfedu.service.IUserService" id="userService" />
</beans>

六.启动运行测试

1.启动zookeeper

2.启动provider对应的tomcat

3.启动protal消费者对应的tomcat

4.在浏览器中输入http://localhost/Users

5.页面上得到数据对应的json

[{"userId":"20190514112608","username":"张三","password":"zhangsan","email":"zhangsan@163.com","tel":"13679189439","level":1,"integral":0,"ifNew":1},
{"userId":"20190516203155","username":"东方不败","password":"222222","email":"gg@163.com","tel":"15536541234","level":1,"integral":0,"ifNew":1},
{"userId":"20190516205310","username":"张无忌","password":"222222","email":"hei@163.com","tel":"17755421234","level":1,"integral":0,"ifNew":1},
{"userId":"20190516205311","username":"路飞","password":"222222","email":"lf@163.com","tel":"13715546631","level":1,"integral":0,"ifNew":1},
{"userId":"20190516205403","username":"吸氧羊","password":"222222","email":"miemie@163.com","tel":"1235468798","level":1,"integral":0,"ifNew":1},
{"userId":"20190516205431","username":"路飞","password":"222222","email":"lf@163.com","tel":"13715546631","level":1,"integral":0,"ifNew":0},
{"userId":"20190516205457","username":"蓝猫","password":"222222","email":"135445888@qq.com","tel":"15315468536","level":1,"integral":0,"ifNew":0},
{"userId":"20190516205513","username":"蔡文姬","password":"222222","email":"cc@163.com","tel":"18312546321","level":1,"integral":0,"ifNew":0},
{"userId":"20190516205530","username":"索隆","password":"222222","email":"sl@163.com","tel":"15545876652","level":1,"integral":0,"ifNew":0},
{"userId":"20190516205542","username":"乌索普","password":"222222","email":"wspp@163.com","tel":"13865421355","level":1,"integral":0,"ifNew":0},
{"userId":"20190516205551","username":"卡普","password":"222222","email":"kp@163.com","tel":"18354568796","level":1,"integral":0,"ifNew":0},
{"userId":"20190516205603","username":"黄猿","password":"222222","email":"hy@163.com","tel":"13754632156","level":1,"integral":0,"ifNew":0},
{"userId":"20190516205613","username":"乔巴","password":"123","email":"qb@163.com","tel":"13154897845","level":1,"integral":0,"ifNew":0},
{"userId":"20190516205624","username":"艾斯","password":"222222","email":"aisi@163.com","tel":"15487965456","level":1,"integral":0,"ifNew":0},
{"userId":"20190516205633","username":"赤犬","password":"222222","email":"cq@163.com","tel":"13896421564","level":1,"integral":0,"ifNew":0},
{"userId":"20190516205654","username":"多弗朗明哥","password":"222222","email":"duoduo@163.com","tel":"13548976523","level":1,"integral":0,"ifNew":0}]

6.至此SSM整合dubbo完成

7.如果想分别监控提供者和消费者,可以配置dubbo-admin的war包来启动服务监控消费者和提供者

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,496评论 6 501
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,407评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,632评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,180评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,198评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,165评论 1 299
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,052评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,910评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,324评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,542评论 2 332
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,711评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,424评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,017评论 3 326
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,668评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,823评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,722评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,611评论 2 353