Dubbo实战案例01【需求分析及项目创建】


文章目录

   一、案例介绍

       1.1 需求

       1.2 项目架构方式

       1.3 技术选型

   二、创建表

   三、项目设计

   四、创建项目

       1.创建dubbo-parent

           1.1 创建项目

           1.2 修改POM文件

       2.创建dubbo-pojo

           2.1 创建项目

           2.2 创建实体类

       3.创建dubbo-mapper

           3.1 创建项目

           3.2 创建UserMapper接口

           3.3 创建 UsersMapper 映射配置文件

           3.4 4修改 POM 文件

       4.创建服务提供者相关项目

           4.1创建dubbo-user-provider

               4.1.1 创建项目

           4.2创建dubbo-user-interface

               4.2.1 创建项目

               4.2.2 修改POM文件

           4.3创建dubbo-user-service

               4.3.1 创建项目

               4.3.2 修改POM文件

               4.3.3 配置MyBatis与Dubbo

                   db.properties

                   applicationContext-dao.xml

                   applicationContext-service.xml

                   applicationContext-trans.xml

                   SqlMapperClient.xml

                   application-dubbo.xml

               4.3.3 测试整合

       5.创建服务消费者相关项目

           5.1创建dubbo-user-consumer

               5.1.1 创建项目

           5.2创建dubbo-user-portal-service

               5.2.1 创建项目

               5.2.2 修改POM文件

           5.3创建dubbo-user-portal

               5.3.1 创建项目(war)

               5.3.2 修改POM文件

               5.3.3 配置 SpringMVC,Spring,web.xml,Dubbo

                   applicationContext-dubbo.xml

                   applicationContext-service.xml

                   springmvc.xml

                   web.xml

               5.3.4 测试整合

一、案例介绍

1.1 需求

 完成对用户表的CRUD操作。

1.2 项目架构方式

 SOA面向服务架构

1.3 技术选型

 maven,Spring,SpringMVC,Mybatis,Dubbo,Zookeeper,MySql

二、创建表

CREATE TABLE `users` (
 `userid` int(11) NOT NULL AUTO_INCREMENT,
 `username` varchar(30) DEFAULT NULL,
 `userage` int(11) DEFAULT NULL,
 PRIMARY KEY (`userid`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

三、项目设计

dubbo-parent (POM)
    |--dubbo-pojo (jar)
    |--dubbo-mapper (jar)
    |--dubbo-user-provider (POM)
        |--dubbo-user-provider-interface (jar)
        |--dubbo-user-provider-service  (jar)
    |--dubbo-user-consumer (pom)
        |--dubbo-user-consumer-portal-service  (jar)
        |--dubbo-user-consumer-protal (war) 

Dubbo实战案例01【需求分析及项目创建】

四、创建项目

1.创建dubbo-parent

1.1 创建项目

Dubbo实战案例01【需求分析及项目创建】Dubbo实战案例01【需求分析及项目创建】

1.2 修改POM文件

<!-- 对依赖的jar包的版本统一进行定义 -->
    <properties>
        <junit.version>4.12</junit.version>
        <spring.version>4.1.3.RELEASE</spring.version>
        <mybatis.version>3.2.8</mybatis.version>
        <mybatis.spring.version>1.2.2</mybatis.spring.version>
        <mysql.version>5.1.32</mysql.version>
        <slf4j.version>1.6.4</slf4j.version>
        <druid.version>1.0.9</druid.version>
        <jstl.version>1.2</jstl.version>
        <servlet-api.version>2.5</servlet-api.version>
        <tomcat.version>2.2</tomcat.version>
        <jsp-api.version>2.0</jsp-api.version>
        <zkClient-version>0.10</zkClient-version>
        <dubbo-version>2.5.4</dubbo-version>
    </properties>


    <!-- jar包的依赖注入 ,由于该工程是一个父工程,所以jar包在该pom文件中只是声明 -->
    <dependencyManagement>
        <dependencies>
            <!-- 单元测试 -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>${junit.version}</version>
            </dependency>
            <!-- 日志处理 -->
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
                <version>${slf4j.version}</version>
            </dependency>
            <!-- Mybatis -->
            <dependency>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis</artifactId>
                <version>${mybatis.version}</version>
            </dependency>
            <dependency>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis-spring</artifactId>
                <version>${mybatis.spring.version}</version>
            </dependency>
            <!-- MySql -->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>${mysql.version}</version>
            </dependency>
            <!-- 连接池 -->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid</artifactId>
                <version>${druid.version}</version>
            </dependency>
            <!-- 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>
            <!-- JSP相关 -->
            <dependency>
                <groupId>jstl</groupId>
                <artifactId>jstl</artifactId>
                <version>${jstl.version}</version>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
                <version>${servlet-api.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>jsp-api</artifactId>
                <version>${jsp-api.version}</version>
                <scope>provided</scope>
            </dependency>
            <!-- dubbo -->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>dubbo</artifactId>
                <version>${dubbo-version}</version>
            </dependency>
            <dependency>
                <groupId>com.101tec</groupId>
                <artifactId>zkclient</artifactId>
                <version>${zkClient-version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                </includes>
            </resource>
        </resources>
        <!-- tomcat插件,由于子项目不一定每个都是web项目,所以该插件只是声明,并未开启 -->
        <pluginManagement>
            <plugins>
                <!-- 配置Tomcat插件 -->
                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>${tomcat.version}</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

2.创建dubbo-pojo

2.1 创建项目

Dubbo实战案例01【需求分析及项目创建】

Dubbo实战案例01【需求分析及项目创建】

2.2 创建实体类

package com.bobo.pojo;

public class User {
    
    private int id;
    
    private String username;
    
    private int userage;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public int getUserage() {
        return userage;
    }

    public void setUserage(int userage) {
        this.userage = userage;
    }
}

Dubbo实战案例01【需求分析及项目创建】

3.创建dubbo-mapper

3.1 创建项目

Dubbo实战案例01【需求分析及项目创建】

3.2 创建UserMapper接口

package com.bobo.mapper;
/**
 * UsersMapper接口文件
 * @author dengp
 *
 */
public interface UsersMapper {

}

3.3 创建 UsersMapper 映射配置文件

<?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="com.bobo.mapper.UsersMapper">

</mapper>

3.4 4修改 POM 文件

<dependencies>
    <dependency>
        <groupId>com.bobo</groupId>
        <artifactId>dubbo-pojo</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
    <!-- Mybatis -->
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis-spring</artifactId>
    </dependency>
    <!-- MySql -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <!-- 连接池 -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid</artifactId>
    </dependency>
</dependencies>
<build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.xml</include>
            </includes>
        </resource>
    </resources>
</build>

4.创建服务提供者相关项目

4.1创建dubbo-user-provider

4.1.1 创建项目

Dubbo实战案例01【需求分析及项目创建】

4.2创建dubbo-user-interface

4.2.1 创建项目

Dubbo实战案例01【需求分析及项目创建】

4.2.2 修改POM文件

<dependencies>
    <!-- 依赖 pojo -->
    <dependency>
        <groupId>com.bobo</groupId>
        <artifactId>dubbo-pojo</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
</dependencies>

4.3创建dubbo-user-service

4.3.1 创建项目

Dubbo实战案例01【需求分析及项目创建】4.3.2 修改POM文件

<dependencies>
    <dependency>
        <groupId>com.bobo</groupId>
        <artifactId>dubbo-user-interface</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>

    <dependency>
        <groupId>com.bobo</groupId>
        <artifactId>dubbo-mapper</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>

    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>dubbo</artifactId>
    </dependency>

    <dependency>
        <groupId>com.101tec</groupId>
        <artifactId>zkclient</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aspects</artifactId>
    </dependency>
</dependencies>

4.3.3 配置MyBatis与Dubbo

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssm?characterEncoding=utf-8
jdbc.username=root
jdbc.password=123456

applicationContext-dao.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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    <!-- 配置解析properties文件的工具类 -->
    <context:property-placeholder location="classpath:db.properties"/>
    
    <!-- 配置数据源 dataSource -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
        <property name="driverClassName" value="${jdbc.driver}" />
        <property name="maxActive" value="10" />
        <property name="minIdle" value="5" />
    </bean>
    
    <!-- 创建mybatis的上下文对象  -->
    <bean class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource">
            <ref bean="dataSource"/>
        </property>
        <property name="configLocation">
            <value>classpath:SqlMapperClient.xml</value>
        </property>
    </bean>
    
    <!-- 扫描mybatis的接口与映射配置文件 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.bobo.mapper"/>
    </bean>
</beans>

applicationContext-service.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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    <!-- 扫描bean对象 -->
    <context:component-scan base-package="com.bobo.dubbo.service.impl"/>
</beans>

applicationContext-trans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
   <!-- 配置事物管理器的切面 --> 
   <bean id="transactionMananger" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>   
   </bean>    
   
   <!-- 配置事物传播行为 :其实就是那些方法应该受什么样的事物控制-->
    <tx:advice id="advice" transaction-manager="transactionMananger">
    <tx:attributes>
        <tx:method name="add*" propagation="REQUIRED"/>
        <tx:method name="modify*" propagation="REQUIRED"/>
        <tx:method name="update*" propagation="REQUIRED"/>
        <tx:method name="dorp*" propagation="REQUIRED"/>
        <tx:method name="del*" propagation="REQUIRED"/>
        <tx:method name="find*" read-only="true"/>
    </tx:attributes>
   </tx:advice>
   
   <!-- 那些类下的方法需要参与到当前的事物管理中 。配置切点 -->
   <aop:config>
    <aop:advisor advice-ref="advice" pointcut="execution(* com.bobo.dubbo.service.impl*.*(..))"/>
   </aop:config>
</beans>

SqlMapperClient.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>

</configuration>

application-dubbo.xml

 服务提供者的配置文件我们放到META-INF/spring/目录下,我们通过main方法启动会自动加载该文件。

Dubbo实战案例01【需求分析及项目创建】

<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
    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/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://code.alibabatech.com/schema/dubbo
        http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
    
    <!-- 导入Spring相关的配置文件 -->
    <import resource="../../applicationContext-dao.xml" />
    <import resource="../../applicationContext-service.xml" />
    <import resource="../../applicationContext-trans.xml" />
    
    <dubbo:application name="user-provider" />
    <dubbo:registry protocol="zookeeper"
        address="192.168.88.171:2181,192.168.88.172:2181,192.168.88.173:2181"/>
        
    <dubbo:protocol name="dubbo" port="20880"/>
</beans>

4.3.3 测试整合

package com.bobo;

import com.alibaba.dubbo.container.Main;

public class Start {

    /**
     * 特点:
     *  1,自带线程阻塞
     *  2,支持优雅关系
     *  Main 类下的 main 方法在启动时默认的回去 classpath:/META-INF/spring/*.xml
     * @param args
     */
    public static void main(String[] args) {
        Main.main(args);
    }
}

Dubbo实战案例01【需求分析及项目创建】

5.创建服务消费者相关项目

 创建消费者相关的服务。

5.1创建dubbo-user-consumer

5.1.1 创建项目

Dubbo实战案例01【需求分析及项目创建】

5.2创建dubbo-user-portal-service

5.2.1 创建项目

Dubbo实战案例01【需求分析及项目创建】

5.2.2 修改POM文件

<dependencies>
    <dependency>
        <groupId>com.bobo</groupId>
        <artifactId>dubbo-user-interface</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.bobo</groupId>
        <artifactId>dubbo-pojo</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
    </dependency>
</dependencies>

5.3创建dubbo-user-portal

5.3.1 创建项目(war)

Dubbo实战案例01【需求分析及项目创建】

5.3.2 修改POM文件

<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>
    <parent>
        <groupId>com.bobo</groupId>
        <artifactId>dubbo-user-consumer</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>dubbo-user-portal</artifactId>
    <packaging>war</packaging>

    <dependencies>
        <!-- 单元测试 -->
        <dependency>
            <groupId>com.bobo</groupId>
            <artifactId>dubbo-user-portal-service</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
        <!-- 日志处理 -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </dependency>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
        </dependency>
        <!-- JSP相关 -->
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- dubbo -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
        </dependency>
        <dependency>
            <groupId>com.101tec</groupId>
            <artifactId>zkclient</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <!-- 配置Tomcat插件 -->
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <configuration>
                    <!-- path: 上传的war包解压后的路径命名 -->
                    <path>/</path>
                    <port>8082</port>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

项目报错手动添加web.xml文件

Dubbo实战案例01【需求分析及项目创建】

5.3.3 配置 SpringMVC,Spring,web.xml,Dubbo

applicationContext-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:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    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/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://code.alibabatech.com/schema/dubbo
        http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
        
    <dubbo:application name="dubbo-consumer"/>
    
    <dubbo:registry  protocol="zookeeper"
        address="192.168.88.171:2181,192.168.88.172:2181,192.168.88.173:2181" /> 

 </beans>

applicationContext-service.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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    <!-- 扫描bean对象 -->
    <context:component-scan base-package="com.bobo.service"/>
</beans>

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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    <!-- 包的扫描器主要是扫描@controller -->
    <context:component-scan base-package="com.bobo.controller" />

    <!-- 注册两个新对象 主要是为了来处理springmvc中的其他anntation 如:@requestmapping -->
    <mvc:annotation-driven />

    <!-- 视图解析器 -->
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!-- jsp所在的前缀 -->
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>
    <!-- 配置静态资源映射 -->
    <mvc:resources location="/WEB-INF/css/" mapping="/css/**" />
    <mvc:resources location="/WEB-INF/js/" mapping="/js/**" />
</beans>

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_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <!-- 上下文参数,告诉Spring配置文件路径 -->
    <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>

    <!-- 配置springmvc -->
    <servlet>
        <servlet-name>springmvc</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>
    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <filter>
        <filter-name>encoding</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>utf-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>


    <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>
</web-app>

5.3.4 测试整合

Dubbo实战案例01【需求分析及项目创建】

访问测试: http://localhost:8082/index

Dubbo实战案例01【需求分析及项目创建】

能够访问说明整合成功~ 下篇介绍具体的业务实现


上一篇:为什么Note.js 里面没有sap.ui.core.Control.extend()这样的代码,但是runtime有自动生成有


下一篇:我的mqtt协议和emqttd开源项目个人理解(23) - websocket客户端连接过程分析(Wireshark抓包+源码分析)