Hey Zookeeper Dubbo
Never underestimate your power to change yourself! – 永远不要低估你改变自我的能力!
大家都知道现在基本的成型的公司,一般都使用了分布式开发,所以今天就带大家通过分布式拆分完成一个基本的案例
基于spring框架,首先创建父类 travel-parent 类型是pom聚和类 里面存储的是 依赖包的版本 方便管理
依赖包
<groupId>com.test.travel</groupId>
<artifactId>travel-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<!--
这是整个项目的父类 并且是聚合类 里面包括了 所有的依赖包的 版本
-->
<packaging>pom</packaging>
<!-- 集中定义依赖版本号 -->
<properties>
<junit.version>4.12</junit.version>
<spring.version>4.3.11.RELEASE</spring.version>
<mybatis.version>3.4.2</mybatis.version>
<mybatis.spring.version>1.3.0</mybatis.spring.version>
<mysql.version>5.1.32</mysql.version>
<slf4j.version>1.6.1</slf4j.version>
<jackson.version>2.7.4</jackson.version>
<jstl.version>1.2</jstl.version>
<servlet-api.version>3.1.0</servlet-api.version>
<pagehelper.version>5.0.3</pagehelper.version>
<druid.version>1.0.29</druid.version>
<dubbo.version>2.5.7</dubbo.version>
<zookeeper.version>3.4.10</zookeeper.version>
<zkclient.version>0.1</zkclient.version>
<commons-fileupload.version>1.3.1</commons-fileupload.version>
<fastdfs_client.version>1.25</fastdfs_client.version>
<jedis.version>2.7.2</jedis.version>
<solr.version>5.5.5</solr.version>
<activemq.version>5.11.2</activemq.version>
<freemarker.version>2.3.23</freemarker.version>
<quartz.version>2.2.3</quartz.version>
<net.version>3.6</net.version>
</properties>
<dependencyManagement>
<dependencies>
<!--日志包-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!--servlet-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet-api.version}</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.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>
<!--mybatis分页插件-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>${pagehelper.version}</version>
</dependency>
<!--mysql驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.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-web</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-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Jackson Json处理工具包 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>${spring.version}</version>
</dependency>
<!--数据源-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.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>${dubbo.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
<exclusion>
<groupId>org.mortbay.jetty</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>${zookeeper.version}</version>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>${zkclient.version}</version>
</dependency>
<!-- fastdfs -->
<dependency>
<groupId>fastdfs_client</groupId>
<artifactId>fastdfs_client</artifactId>
<version>${fastdfs_client.version}</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>${commons-fileupload.version}</version>
</dependency>
<!--Jedis的jar-->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${jedis.version}</version>
</dependency>
<!--solr-->
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>${solr.version}</version>
</dependency>
<!--junit测试-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!--ActiveMQ-->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>${activemq.version}</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>${freemarker.version}</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>${quartz.version}</version>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>${net.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<!-- java编译插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!-- 配置Tomcat插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
里面的dependencyManagement与 dependencies的区别是:
dependencyManagement里只是声明依赖,并不实现引入,因此子项目需要显式的声明需要用的依赖.如果不在子项目中声明依赖,是不会从父项目中继承下来的;只有在子项目中写了该依赖项,并且没有指定具体版本,才会从父项目中继承该项,并且version和scope都读取自父pom;另外如果子项目中指定了版本号,那么会使用子项目中指定的jar版本.
dependencies即使在子模块中不写该依赖项,那么子模块仍然会从父项目中继承该依赖项(全部继承)
写完parent后 进行clean 然后 install
继续写 实体类和工具类 travel-common 是个 类型是jar的形式,父类是 parent
<artifactId>travel-common</artifactId>
<version>1.0-SNAPSHOT</version>
<!--
实体类的 工程类 依赖 父类的包
-->
<parent>
<groupId>com.test.travel</groupId>
<artifactId>travel-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
实体类 注意实现 序列化接口
public class City implements Serializable {
private Integer id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
编写业务层,以及数据层 travel-manager 这是个 pom聚合类 里面有三个模块,数据层,接口层,业务层,依赖父类以及 实体类
<groupId>com.test.travel</groupId>
<artifactId>travel-manager</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<module>travel-manager-dao</module>
<module>travel-manager-interface</module>
<module>travel-manager-service</module>
</modules>
<packaging>pom</packaging>
<!--
父类
-->
<parent>
<groupId>com.test.travel</groupId>
<artifactId>travel-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<!--
依赖 实体类
-->
<dependencies>
<dependency>
<groupId>com.test.travel</groupId>
<artifactId>travel-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
三个模块中的 数据层的实现 travel-manager-dao 依赖mybatis 是个jar包 pom 文件如下
<parent>
<artifactId>travel-manager</artifactId>
<groupId>com.test.travel</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<!--
这是 数据层,需要连接数据库 是个jar 包 依赖 Mybatis
-->
<artifactId>travel-manager-dao</artifactId>
<dependencies>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</dependency>
</dependencies>
<!--
扫mapper
-->
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
数据层的接口以及实现Mapper文件
public interface CityMapper {
void addCity(String name);
void updateCity(City city);
void deleteCity(Integer id);
List<City> getCityList();
}
Mapper
<mapper namespace="com.test.travel.manager.dao.CityMapper">
<!--
id必须和接口中对应方法的名字一样
parameterType 必须和方法的参数一致
resultType必须和方法的返回值一致
-->
<resultMap id="cityMap" type="com.test.travel.common.pojo.City">
<id property="id" column="ID"/>
<result property="name" column="NAME"/>
</resultMap>
<select id="getCityList" resultMap="cityMap" parameterType="com.test.travel.common.pojo.City">
select ID, NAME from CITY
<where>
<if test="id !=null"> and ID=#{id}</if>
<if test="name !=null and name!=''"> and NAME like concat('%',#{name},'%')</if>
</where>
</select>
<insert id="addCity" parameterType="String" useGeneratedKeys="true">
insert into CITY(NAME) values (#{name})
</insert>
<update id="updateCity" parameterType="com.test.travel.common.pojo.City">
update CITY
set NAME=#{name}
where ID=#{id}
</update>
<delete id="deleteCity" parameterType="int">
delete from CITY where ID=#{id}
</delete>
</mapper>
三大模块 之 业务接口的实现 是个jar类型 pom文件如下
<parent>
<artifactId>travel-manager</artifactId>
<groupId>com.test.travel</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<!--
业务层的 接口 也是 jar包
-->
<packaging>jar</packaging>
<artifactId>travel-manager-interface</artifactId>
具体接口如下:
public interface CityService {
void addCity(String name);
void updateCity(City city);
void deleteCity(Integer id);
List<City> getCityList();
}
三大模块中的 业务实现类 也是最重要的一个模块 其进行了发布到zookeeper中,使用了dubbo,所以他是一个war包的形式 ,依赖数据层,以及业务接口层,依赖jar包 其 pom 文件如下:
<parent>
<artifactId>travel-manager</artifactId>
<groupId>com.test.travel</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<!--
业务接口的 实现类 是 war包形式 需要发布到 Dubbo 中去
-->
<packaging>war</packaging>
<artifactId>travel-manager-service</artifactId>
<dependencies>
<!--
依赖的 接口 以及数据层
-->
<dependency>
<groupId>com.test.travel</groupId>
<artifactId>travel-manager-interface</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.test.travel</groupId>
<artifactId>travel-manager-dao</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!--spring相关-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
</dependency>
<!--数据库驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--数据库连接池-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<!--dubbo服务相关-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<port>8080</port>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
具体代码如下: 业务实现类
@Service
public class CityServiceImpl implements CityService {
// 通过spring的方式进行创建类
@Autowired
private CityMapper cityMapper;
@Override
public void addCity(String name) {
cityMapper.addCity(name);
}
@Override
public void updateCity(City city) {
cityMapper.updateCity(city);
}
@Override
public void deleteCity(Integer id) {
cityMapper.deleteCity(id);
}
@Override
public List<City> getCityList() {
return cityMapper.getCityList();
}
}
配置文件 基本配置如下: 需要 jdbc.properties数据库 以及log4j.properties打印日志的配置文件
// 加载 配置文件
<context:property-placeholder location="classpath:jdbc.properties" ignore-unresolvable="true"/>
// 配置 连接池
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
// 配置会话工厂
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
// 进行 加载 Mapper.xml 文件 以及 实体类
<property name="mapperLocations" value="classpath:com/test/travel/manager/dao/*.xml"/>
<property name="typeAliasesPackage" value="com.test.travel.common.pojo"/>
</bean>
<!--批量扫描dao的接口 就是Mapper-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.test.travel.manager.dao"/>
</bean>
// 事务管理器
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
// 事务的具体 配置
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" rollback-for="Exception"/>
<tx:method name="delete*" rollback-for="Exception"/>
<tx:method name="update*" rollback-for="Exception"/>
<tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
</tx:attributes>
</tx:advice>
// AOP切面编程
<aop:config>
<aop:pointcut id="point" expression="execution(* com.test.travel.manager.service..*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="point"/>
</aop:config>
</beans>
继续配置 Dubbo以及 Zookeeper的配置文件:
<?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.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!--扫描所有的service-->
<context:component-scan base-package="com.test.travel.manager.service">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/>
</context:component-scan>
<!-- 发布dubbo服务 -->
<!-- 提供方应用信息,用于计算依赖关系 -->
<dubbo:application name="travel-manager" />
<!-- 注册中心的地址 -->
<dubbo:registry protocol="zookeeper" address="你的域名ip:端口" />
<!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="20880" />
// 需要把这个 实现类进行注册到 Zookeeper中
<dubbo:service interface="com.test.travel.manager.service.CityService" ref="cityServiceImpl"
timeout="300000"/>
</beans>
接下来就是 加载这些配置文件了 在travel-manager-service业务实现模块中进行使用webapp加载文件
<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"
metadata-complete="true">
<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>
之后就可已启动该项目了,然后作为提供者进行提供接口,再写一个消费者,就是controller来实现该业务.
创建一个travel-manager-web项目 里面包含了controller ,其类型也是war,其pom文件如下:
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.travel</groupId>
<artifactId>travel-manager-web</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<!--
controller层
-->
<!--
父类以及 引用类
-->
<parent>
<groupId>com.test.travel</groupId>
<artifactId>travel-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<dependencies>
<!--通用工程,实体类和工具类-->
<dependency>
<groupId>com.test.travel</groupId>
<artifactId>travel-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!--后台接口工程-->
<dependency>
<groupId>com.test.travel</groupId>
<artifactId>travel-manager-interface</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!--springMVC-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<!-- JSP相关 -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!--servlet-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<!--期望JDK、容器或使用者会提供这个依赖,否则会与tomcat插件冲突-->
<scope>provided</scope>
</dependency>
<!--dubbo服务相关-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>
<build>
<finalName>travel-manager-web</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<port>8081</port>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
集体实现类:
@RestController
@RequestMapping("/city")
public class CityController {
@Autowired
private CityService cityService;
@RequestMapping("/citylist.html")
public List<City> getAllCity(){
return cityService.getCityList();
}
}
配置文件如下: 起一个 springMVC-servlet.xml 的文件 用来存放该配置,在WEB-INF目录下,DispatcherServlet会默认加载-servlet.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"
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.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<!-- 启动自动扫描 -->
<context:component-scan base-package="com.test.travel.manager.controller">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<mvc:annotation-driven content-negotiation-manager="contentNegotiationManagerFactoryBean">
</mvc:annotation-driven>
<!--配置返回值转换器-->
<bean id="contentNegotiationManagerFactoryBean"
class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<!--是否支持后缀匹配-->
<property name="favorPathExtension" value="false"/>
<!--是否支持参数匹配-->
<property name="favorParameter" value="false"/>
<!--是否accept-header匹配-->
<property name="ignoreAcceptHeader" value="false"/>
<!--支持json格式-->
<property name="mediaTypes">
<map>
<entry key="json" value="application/json"/>
</map>
</property>
</bean>
<!-- 引用dubbo服务 -->
<dubbo:application name="travel-manager-web"/>
<dubbo:registry protocol="zookeeper" address="目标地址:端口号"/>
<dubbo:reference interface="com.test.travel.manager.service.CityService" id="cityService"/>
</beans>
其web.xml文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<!--配置DispatcherServlet -->
<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>-->
</servlet>
<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<!--解决乱码-->
<filter>
<filter-name>EncodingFilter</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>EncodingFilter</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>
</web-app>
之后启动然后访问该 Controller的接口就OK了,这样就完成了基本的拆分. 最近这段时间,我会整理一个关于分布式的文档,让大家能够简单了解其原理,以便更好地使用.