SSM三大框架整合教程

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
服务治理 MSE Sentinel/OpenSergo,Agent数量 不受限
简介: SSM框架,是Spring + Spring MVC + MyBatis的缩写,这个是继SSH之后,目前比较主流的Java EE企业级框架,适用于搭建各种大型的企业级应用系统。

      SSM框架,是Spring + Spring MVC + MyBatis的缩写,这个是继SSH之后,目前比较主流的Java EE企业级框架,适用于搭建各种大型的企业级应用系统。

      相关视频推荐:https://www.bilibili.com/video/BV1Ug4y1i7W7


1、 准备环境

为每个War包工程创建一个Server

图片.png


image.gif那么 添加了Server后需要对每一个Server进行配置:

以console为例子:

设置timeout的时间为300


图片.png


去掉项目名

图片.png


剩下的几个Server 需要改端口号:

图片.png


2, 导入Jar包
在父工程的pom文件中导入项目开发所需要的jar包:
pom.xml:

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>cn.itcast.babasport</groupId>
  4   <artifactId>parentProject</artifactId>
  5   <version>0.0.1-SNAPSHOT</version>
  6   <packaging>pom</packaging>
  7   <modules>
  8       <module>babasport-common</module>
  9       <module>babasport-javaBean</module>
 10       <module>babasport-dao</module>
 11       <module>babasport-service-interface</module>
 12       <module>babasport-portal</module>
 13       <module>babasport-console</module>
 14       <module>babasport-login</module>
 15       <module>babasport-service-product</module>
 16       <module>babasport-service-buyer</module>
 17       <module>babasport-service-solr</module>
 18       <module>babasport-service-cms</module>
 19   </modules>
 20   
 21       <!-- jdk1.7 -->
 22     <build>
 23         <plugins>
 24             <plugin>
 25                 <groupId>org.apache.maven.plugins</groupId>
 26                 <artifactId>maven-compiler-plugin</artifactId>
 27                 <version>3.2</version>
 28                 <configuration>
 29                     <source>1.7</source>
 30                     <target>1.7</target>
 31                     <encoding>UTF-8</encoding>
 32                 </configuration>
 33             </plugin>
 34         </plugins>
 35     </build>
 36     
 37     <!-- 设置统一控制版本 -->
 38     <properties>
 39         <java-version>1.7</java-version>
 40         <junit-version>4.12</junit-version>
 41         <spring.version>4.1.3.RELEASE</spring.version>
 42         <jackson.version>2.4.2</jackson.version>
 43         <mysql-connector-java-version>5.1.8</mysql-connector-java-version>
 44         <org.mybatis-version>3.2.7</org.mybatis-version>
 45         <org.mybatis-spring-version>1.2.2</org.mybatis-spring-version>
 46         <opensymphony-version>2.4.2</opensymphony-version>
 47         <freemarker-version>2.3.18</freemarker-version>
 48         <druid.version>1.0.9</druid.version>
 49         <commons-collections-version>1.0</commons-collections-version>
 50         <commons-fileupload-version>1.2.2</commons-fileupload-version>
 51         <org.apache.commons-version>3.1</org.apache.commons-version>
 52         <commons-codec-version>1.6</commons-codec-version>
 53         <dom4j-version>1.6.1</dom4j-version>
 54         <javax.servlet-version>1.2</javax.servlet-version>
 55         <aspectjweaver-version>1.6.6</aspectjweaver-version>
 56         <slf4j-log4j12-version>1.6.6</slf4j-log4j12-version>
 57         <log4j-version>1.2.16</log4j-version>
 58         <javax.servlet-jsp-version>2.0</javax.servlet-jsp-version>
 59         <cglib-version>2.2.2</cglib-version>
 60         <slf4j-api-version>1.6.6</slf4j-api-version>
 61         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 62     </properties>
 63     
 64     <!-- 依赖管理 版本号 -->
 65     <!-- 设置统一依赖管理、不强行依赖 -->
 66     <dependencyManagement>
 67         <dependencies>
 68             <!-- with junit4.8.2 -->
 69             <dependency>
 70                 <groupId>junit</groupId>
 71                 <artifactId>junit</artifactId>
 72                 <version>${junit-version}</version>
 73                 <type>jar</type>
 74             </dependency>
 75             <!-- Spring -->
 76             <dependency>
 77                 <groupId>org.springframework</groupId>
 78                 <artifactId>spring-context</artifactId>
 79                 <version>${spring.version}</version>
 80             </dependency>
 81             <dependency>
 82                 <groupId>org.springframework</groupId>
 83                 <artifactId>spring-beans</artifactId>
 84                 <version>${spring.version}</version>
 85             </dependency>
 86             <dependency>
 87                 <groupId>org.springframework</groupId>
 88                 <artifactId>spring-webmvc</artifactId>
 89                 <version>${spring.version}</version>
 90             </dependency>
 91             <dependency>
 92                 <groupId>org.springframework</groupId>
 93                 <artifactId>spring-jdbc</artifactId>
 94                 <version>${spring.version}</version>
 95             </dependency>
 96             <dependency>
 97                 <groupId>org.springframework</groupId>
 98                 <artifactId>spring-aspects</artifactId>
 99                 <version>${spring.version}</version>
100             </dependency>
101 
102             <dependency>
103                 <groupId>org.springframework</groupId>
104                 <artifactId>spring-test</artifactId>
105                 <version>${spring.version}</version>
106             </dependency>
107 
108             <dependency>
109                 <groupId>org.springframework</groupId>
110                 <artifactId>spring-context-support</artifactId>
111                 <version>${spring.version}</version>
112             </dependency>
113 
114             <dependency>
115                 <groupId>org.springframework</groupId>
116                 <artifactId>spring-jms</artifactId>
117                 <version>${spring.version}</version>
118             </dependency>
119 
120 
121             <!-- Jackson Json处理工具包 -->
122             <dependency>
123                 <groupId>com.fasterxml.jackson.core</groupId>
124                 <artifactId>jackson-databind</artifactId>
125                 <version>${jackson.version}</version>
126             </dependency>
127 
128             <!--freemarker -->
129             <dependency>
130                 <groupId>org.freemarker</groupId>
131                 <artifactId>freemarker</artifactId>
132                 <version>2.3.18</version>
133             </dependency>
134             <!-- with mybatis-spring -->
135             <dependency>
136                 <groupId>org.mybatis</groupId>
137                 <artifactId>mybatis</artifactId>
138                 <version>${org.mybatis-version}</version>
139             </dependency>
140             <dependency>
141                 <groupId>org.mybatis</groupId>
142                 <artifactId>mybatis-spring</artifactId>
143                 <version>${org.mybatis-spring-version}</version>
144             </dependency>
145             <!-- jdbc driver -->
146             <dependency>
147                 <groupId>mysql</groupId>
148                 <artifactId>mysql-connector-java</artifactId>
149                 <version>${mysql-connector-java-version}</version>
150             </dependency>
151             <!-- 连接池 -->
152             <dependency>
153                 <groupId>com.alibaba</groupId>
154                 <artifactId>druid</artifactId>
155                 <version>${druid.version}</version>
156             </dependency>
157             <!-- apache commons jar -->
158             <dependency>
159                 <groupId>commons-collections</groupId>
160                 <artifactId>commons-collections</artifactId>
161                 <version>${commons-collections-version}</version>
162             </dependency>
163 
164             <dependency>
165                 <groupId>commons-fileupload</groupId>
166                 <artifactId>commons-fileupload</artifactId>
167                 <version>${commons-fileupload-version}</version>
168             </dependency>
169 
170             <dependency>
171                 <groupId>org.apache.commons</groupId>
172                 <artifactId>commons-lang3</artifactId>
173                 <version>${org.apache.commons-version}</version>
174             </dependency>
175 
176             <dependency>
177                 <groupId>commons-codec</groupId>
178                 <artifactId>commons-codec</artifactId>
179                 <version>${commons-codec-version}</version>
180             </dependency>
181             <!-- analyze xml use dom4j -->
182             <dependency>
183                 <groupId>dom4j</groupId>
184                 <artifactId>dom4j</artifactId>
185                 <version>${dom4j-version}</version>
186             </dependency>
187 
188             <!-- jstl标签 -->
189             <dependency>
190                 <groupId>jstl</groupId>
191                 <artifactId>jstl</artifactId>
192                 <version>1.2</version>
193             </dependency>
194             <dependency>
195                 <groupId>taglibs</groupId>
196                 <artifactId>standard</artifactId>
197                 <version>1.1.2</version>
198             </dependency>
199 
200             <dependency>
201                 <groupId>org.slf4j</groupId>
202                 <artifactId>slf4j-log4j12</artifactId>
203                 <version>1.6.6</version>
204             </dependency>
205             <dependency>
206                 <groupId>log4j</groupId>
207                 <artifactId>log4j</artifactId>
208                 <version>1.2.17</version>
209             </dependency>
210 
211             <dependency>
212                 <groupId>org.slf4j</groupId>
213                 <artifactId>slf4j-api</artifactId>
214                 <version>1.6.6</version>
215             </dependency>
216             <dependency>
217                 <groupId>javax.activation</groupId>
218                 <artifactId>activation</artifactId>
219                 <version>1.1.1</version>
220             </dependency>
221 
222             <dependency>
223                 <groupId>cglib</groupId>
224                 <artifactId>cglib</artifactId>
225                 <version>${cglib-version}</version>
226             </dependency>
227 
228             <dependency>
229                 <groupId>net.fckeditor</groupId>
230                 <artifactId>java-core</artifactId>
231                 <version>2.6</version>
232             </dependency>
233 
234             <dependency>
235                 <groupId>org.json</groupId>
236                 <artifactId>json</artifactId>
237                 <version>20131018</version>
238             </dependency>
239 
240             <!--page -->
241             <dependency>
242                 <groupId>com.babasport</groupId>
243                 <artifactId>page</artifactId>
244                 <version>1.0</version>
245             </dependency>
246             <!-- solrJ -->
247             <dependency>
248                 <groupId>org.apache.solr</groupId>
249                 <artifactId>solr-solrj</artifactId>
250                 <version>4.10.3</version>
251             </dependency>
252 
253             <!-- jedis Java接口 -->
254             <dependency>
255                 <groupId>redis.clients</groupId>
256                 <artifactId>jedis</artifactId>
257                 <version>2.6.2</version>
258                 <type>jar</type>
259             </dependency>
260 
261             <!-- FastDFS client -->
262 
263             <dependency>
264                 <groupId>fastdfs_client</groupId>
265                 <artifactId>fastdfs_client</artifactId>
266                 <version>1.20</version>
267             </dependency>
268 
269             <dependency>
270                 <groupId>org.jboss.netty</groupId>
271                 <artifactId>netty</artifactId>
272                 <version>3.2.5.Final</version>
273             </dependency>
274 
275             <dependency>
276                 <groupId>com.alibaba</groupId>
277                 <artifactId>dubbo</artifactId>
278                 <version>2.5.3</version>
279             </dependency>
280 
281             <dependency>
282                 <groupId>com.alibaba</groupId>
283                 <artifactId>fastjson</artifactId>
284                 <version>1.1.41</version>
285             </dependency>
286 
287             <!-- Zookeeper 用于分布式服务管理 -->
288 
289             <dependency>
290                 <groupId>com.github.sgroschupf</groupId>
291                 <artifactId>zkclient</artifactId>
292                 <version>0.1</version>
293             </dependency>
294             <dependency>
295                 <groupId>org.apache.zookeeper</groupId>
296                 <artifactId>zookeeper</artifactId>
297                 <version>3.4.6</version>
298             </dependency>
299             <!-- Zookeeper 用于分布式服务管理 end -->
300             <!-- Active MQ 开始 -->
301             <dependency>
302                 <groupId>org.apache.activemq</groupId>
303                 <artifactId>activemq-all</artifactId>
304                 <version>5.8.0</version>
305             </dependency>
306             <dependency>
307                 <groupId>org.apache.activemq</groupId>
308                 <artifactId>activemq-pool</artifactId>
309                 <version>5.8.0</version>
310             </dependency>
311             <!-- Active MQ 结束 -->
312             <!-- Tomcat7 servlet-api -->
313             <dependency>
314                 <groupId>org.apache.tomcat</groupId>
315                 <artifactId>tomcat-jsp-api</artifactId>
316                 <version>7.0.47</version>
317                 <scope>provided</scope>
318             </dependency>
319         </dependencies>
320     </dependencyManagement>
321 </project>
pom.xml


3,Druid

以往配置数据库连接池我们大多使用C3P0,jdbc等, 但是现在开始使用Druid.

图片.png


4, Servlet-api.jar

把这个jar包单独拿出来提是因为在Tomcat 7中 使用的是3.0版本, 而我们通过pom导入的只能够是2.5, 所以这里Apache专门开发了一个jar包来替代这个.(这里所说的替代只是在编码中可以使用, 添加了provided关键字, 并不会被编译)

需要在在每个子项目pom.xml添加:

 <!-- Tomcat7 servlet-api -->
 <dependency>
     <groupId>org.apache.tomcat</groupId>
     <artifactId>tomcat-jsp-api</artifactId>
    <scope>provided</scope>
</dependency>


5, 整合Spring+Mybatis

Babasport-service-product  为安例进行整合

图片.png

想看一眼product目录结构:

图片.png


web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">
    <!-- 上下文的位置 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:application-context.xml</param-value>
    </context-param>
    <!-- Spring监听器 -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
</web-app>


application-context.xml:spring配置文件

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:task="http://www.springframework.org/schema/task"
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-4.0.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-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/task
           http://www.springframework.org/schema/task/spring-task-4.0.xsd
        http://code.alibabatech.com/schema/dubbo        
        http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
        <!-- 配置 连接池 事务 扫描 读取jdbc.properties mybatis工厂  solr redis-->
        <import resource="config/*.xml"/>
</beans>


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>
    <!-- 别名 -->
    <typeAliases>
        <package name="cn.itcast.core.bean"/>
    </typeAliases>
    <!-- Mapper.xml所在位置
    <mappers>
        <package name="cn.itcast.core.dao"/>
    </mappers>
    -->
</configuration>


anoaction.xml: 扫描设置

 <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:task="http://www.springframework.org/schema/task"
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.0.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-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/task
           http://www.springframework.org/schema/task/spring-task-4.0.xsd
        http://code.alibabatech.com/schema/dubbo
        http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
        <!-- 配置扫描-->
        <context:component-scan base-package="cn.itcast"/>
</beans>


jdbc.xml: JDBC配置文件

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:task="http://www.springframework.org/schema/task"
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.0.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-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/task
           http://www.springframework.org/schema/task/spring-task-4.0.xsd
        http://code.alibabatech.com/schema/dubbo
        http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
        <!-- 配置 连接池 使用druid连接池-->
        <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
            <!-- 驱动 -->
            <property name="driverClassName" value="${driverClassName}"/>
            <property name="url" value="${url}"/>
            <property name="username" value="${username}"/>
            <property name="password" value="${password}"/>
        </bean>
</beans>


mybatis.xml: mybatis配置文件

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:task="http://www.springframework.org/schema/task"
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.0.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-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/task
           http://www.springframework.org/schema/task/spring-task-4.0.xsd
        http://code.alibabatech.com/schema/dubbo
        http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
        <!-- 配置mybatis-->
        <bean class="org.mybatis.spring.SqlSessionFactoryBean">
            <!-- 数据源 -->
            <property name="dataSource" ref="dataSource"/>
            <!-- 配置Mybatis配置文件所在位置 -->
            <property name="configLocation" value="classpath:mybatis-config.xml"></property>
        </bean>
        <!-- 三种:
            第一种:原始Dao:接口实现类 Mapper.xml
            第二种:接口Mapper.xml(需要重复配置)
            第三种:第二种升级版,扫描方式自动加载Dao接口Mapper,不用一个一个的配置,扫描的包
                注意事项:Dao接口和Mapper文件在同一目录下(包下),并且UserDao.java UserDao.xml 同名
        -->
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <property name="basePackage" value="cn.itcast.core.dao"/>
        </bean>
</beans>


properties.xml: 读取属性文件

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:task="http://www.springframework.org/schema/task"
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.0.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-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/task
           http://www.springframework.org/schema/task/spring-task-4.0.xsd
        http://code.alibabatech.com/schema/dubbo
        http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
        <!-- 读取properties文件 -->
        <!-- <context:property-placeholder location="classpath:jdbc.properties"/> -->
        <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="locations">
                <list>
                    <value>classpath:jdbc.properties</value>
                </list>
            </property>
        </bean>
</beans>


transaction.xml:事务配置文件

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:task="http://www.springframework.org/schema/task"
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.0.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-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/task
           http://www.springframework.org/schema/task/spring-task-4.0.xsd
        http://code.alibabatech.com/schema/dubbo
        http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
        <!-- 配置事务-->
        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource"></property>
        </bean>
        <!-- @Transaction 开启事务注解 -->
        <tx:annotation-driven transaction-manager="transactionManager"/>
</beans>


6, 整合Spring

Login/Console/Portal 都是输入Controller层, 所以这三个project都需要做此配置.
这里以Console为例子:

先看一下Console project整体目录结构:

图片.png

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">
    <!-- 前端控制器 -->
    <servlet>
        <servlet-name>console</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <!-- 默认读取的是 WEB-INF/console-servlet.xml -->
            <param-value>classpath:springmvc-console.xml</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>console</servlet-name>
        <!--
            /*: 拦截视图请求: .jsp  .js  .css  几乎不用,配置静态资源过滤
            /: 拦截所有,不拦截.jsp 文件, 但是同样拦截.js .css  如果使用也需要配置静态资源过滤(前台系统使用)
            *.do:拦截所有以.do请求, 后台开发应用*.do
         -->
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
</web-app>


springmvc-console.xml:Springmvc配置文件

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:task="http://www.springframework.org/schema/task"
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.0.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-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/task
           http://www.springframework.org/schema/task/spring-task-4.0.xsd
        http://code.alibabatech.com/schema/dubbo
        http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
    <!-- 扫描@Controller -->
    <context:component-scan base-package="cn.itcast"/>
    <!-- 处理器适配器 映射器 -->
    <mvc:annotation-driven/>
    <!-- jsp视图解析器 -->
    <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/console/"/>
        <property name="suffix" value=".jsp"/>
    </bean>
    <import resource="dubbo-customer.xml"/>
</beans>

到了这里三大框架就整合完了, 下一篇将带来Dubbo和Zookeeper的使用.

相关实践学习
基于MSE实现微服务的全链路灰度
通过本场景的实验操作,您将了解并实现在线业务的微服务全链路灰度能力。
相关文章
|
4月前
|
Java
SSM框架整合
SSM框架整合
41 3
|
30天前
|
Java 数据库连接 Maven
手把手教你如何搭建SSM框架、图书商城系统案例
这篇文章是关于如何搭建SSM框架以及实现一个图书商城系统的详细教程,包括了项目的配置文件整合、依赖管理、项目结构和运行效果展示,并提供了GitHub源码链接。
手把手教你如何搭建SSM框架、图书商城系统案例
|
3月前
|
JSON 前端开发 Java
手把手整合SSM框架2
手把手整合SSM框架
48 0
|
3月前
|
Java 数据库连接 Maven
手把手整合SSM框架1
手把手整合SSM框架
45 0
|
1月前
|
Java 数据库连接 Spring
后端框架入门超详细 三部曲 Spring 、SpringMVC、Mybatis、SSM框架整合案例 【爆肝整理五万字】
文章是关于Spring、SpringMVC、Mybatis三个后端框架的超详细入门教程,包括基础知识讲解、代码案例及SSM框架整合的实战应用,旨在帮助读者全面理解并掌握这些框架的使用。
后端框架入门超详细 三部曲 Spring 、SpringMVC、Mybatis、SSM框架整合案例 【爆肝整理五万字】
|
1月前
|
Java 数据库连接 Maven
SSM框架整合图书管理项目
这篇文章是关于SSM框架整合到图书管理项目的详细教程,涵盖了从Maven项目构建、依赖导入、数据库连接、配置文件编写、实体类和接口实现到SpringMVC整合的完整步骤。
SSM框架整合图书管理项目
|
1月前
|
Java 数据库
使用ssm框架搭建的图书管理系统
本文介绍了使用SSM框架搭建的图书管理系统,包括图书信息管理、借阅记录管理、公告管理、出入库管理以及用户管理等功能。
使用ssm框架搭建的图书管理系统
|
3月前
|
SQL 前端开发 Java
基于SSM框架的教务系统
基于SSM框架的教务系统
44 2
基于SSM框架的教务系统
WXM
|
2月前
|
Java 应用服务中间件 网络安全
Eclipse运行SSM/SSH项目教程
Eclipse运行SSM/SSH项目教程
WXM
65 0
|
3月前
|
Java
SSM框架Controller层可以做什么
SSM框架Controller层可以做什么