码迷,mamicode.com
首页 > Web开发 > 详细

[项目构建]babasport SSM 三大框架整合 [练手项目]

时间:2016-08-16 21:32:23      阅读:2025      评论:0      收藏:0      [点我收藏+]

标签:

上一篇已经讲了整个各个子模块的创建过程以及它们之间的依存关系, 那么这一篇就来正式的整合三大框架(SSM)了.

1, 准备环境
1.1 为每个War包工程创建一个Server
技术分享

那么 添加了Server后需要对每一个Server进行配置:
以console为例子:
设置timeout的时间为300
技术分享

去掉项目名
技术分享

剩下的几个Server 需要改端口号:
技术分享

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.
技术分享

4, Servlet-api.jar

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

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

1 <!-- Tomcat7 servlet-api -->
2 <dependency>
3     <groupId>org.apache.tomcat</groupId>
4     <artifactId>tomcat-jsp-api</artifactId>
5     <scope>provided</scope>
6 </dependency>

 


5, 整合Spring+Mybatis

Babasport-service-product  为安例进行整合
技术分享

想看一眼product目录结构:
技术分享

web.xml:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
 5     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 6     
 7     <!-- 上下文的位置 -->
 8     <context-param>
 9         <param-name>contextConfigLocation</param-name>
10         <param-value>classpath:application-context.xml</param-value>
11     </context-param>
12     
13     <!-- Spring监听器 -->
14     <listener>
15         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
16     </listener>
17 </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

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
 3 "http://mybatis.org/dtd/mybatis-3-config.dtd">
 4 
 5 <configuration>
 6     <!-- 别名 -->
 7     <typeAliases>
 8         <package name="cn.itcast.core.bean"/>
 9     </typeAliases>
10     
11     <!-- Mapper.xml所在位置 
12     <mappers>
13         <package name="cn.itcast.core.dao"/>
14     </mappers>
15     -->
16 </configuration>


anoaction.xml: 扫描设置

技术分享
 1 <beans xmlns="http://www.springframework.org/schema/beans"
 2     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
 3     xmlns:context="http://www.springframework.org/schema/context"
 4     xmlns:aop="http://www.springframework.org/schema/aop" 
 5     xmlns:tx="http://www.springframework.org/schema/tx"
 6     xmlns:task="http://www.springframework.org/schema/task"
 7     xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
 8     xsi:schemaLocation="http://www.springframework.org/schema/beans 
 9         http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
10         http://www.springframework.org/schema/mvc 
11         http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
12         http://www.springframework.org/schema/context 
13         http://www.springframework.org/schema/context/spring-context-4.0.xsd 
14         http://www.springframework.org/schema/aop 
15         http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
16         http://www.springframework.org/schema/tx 
17         http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
18         http://www.springframework.org/schema/task
19            http://www.springframework.org/schema/task/spring-task-4.0.xsd
20         http://code.alibabatech.com/schema/dubbo        
21         http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
22         
23         <!-- 配置扫描-->
24         <context:component-scan base-package="cn.itcast"/>
25         
26         
27 </beans>
View Code

jdbc.xml: JDBC配置文件

技术分享
 1 <beans xmlns="http://www.springframework.org/schema/beans"
 2     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
 3     xmlns:context="http://www.springframework.org/schema/context"
 4     xmlns:aop="http://www.springframework.org/schema/aop" 
 5     xmlns:tx="http://www.springframework.org/schema/tx"
 6     xmlns:task="http://www.springframework.org/schema/task"
 7     xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
 8     xsi:schemaLocation="http://www.springframework.org/schema/beans 
 9         http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
10         http://www.springframework.org/schema/mvc 
11         http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
12         http://www.springframework.org/schema/context 
13         http://www.springframework.org/schema/context/spring-context-4.0.xsd 
14         http://www.springframework.org/schema/aop 
15         http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
16         http://www.springframework.org/schema/tx 
17         http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
18         http://www.springframework.org/schema/task
19            http://www.springframework.org/schema/task/spring-task-4.0.xsd
20         http://code.alibabatech.com/schema/dubbo        
21         http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
22         
23         <!-- 配置 连接池 使用druid连接池-->
24         <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
25             <!-- 驱动 -->
26             <property name="driverClassName" value="${driverClassName}"/>
27             <property name="url" value="${url}"/>
28             <property name="username" value="${username}"/>
29             <property name="password" value="${password}"/>
30         </bean>
31         
32 </beans>
View Code

mybatis.xml: mybatis配置文件

技术分享
 1 <beans xmlns="http://www.springframework.org/schema/beans"
 2     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
 3     xmlns:context="http://www.springframework.org/schema/context"
 4     xmlns:aop="http://www.springframework.org/schema/aop" 
 5     xmlns:tx="http://www.springframework.org/schema/tx"
 6     xmlns:task="http://www.springframework.org/schema/task"
 7     xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
 8     xsi:schemaLocation="http://www.springframework.org/schema/beans 
 9         http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
10         http://www.springframework.org/schema/mvc 
11         http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
12         http://www.springframework.org/schema/context 
13         http://www.springframework.org/schema/context/spring-context-4.0.xsd 
14         http://www.springframework.org/schema/aop 
15         http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
16         http://www.springframework.org/schema/tx 
17         http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
18         http://www.springframework.org/schema/task
19            http://www.springframework.org/schema/task/spring-task-4.0.xsd
20         http://code.alibabatech.com/schema/dubbo        
21         http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
22         
23         <!-- 配置mybatis-->
24         <bean class="org.mybatis.spring.SqlSessionFactoryBean">
25             <!-- 数据源 -->
26             <property name="dataSource" ref="dataSource"/>
27             <!-- 配置Mybatis配置文件所在位置 -->
28             <property name="configLocation" value="classpath:mybatis-config.xml"></property>
29         </bean>    
30         
31         <!-- 三种: 
32             第一种:原始Dao:接口实现类 Mapper.xml
33             第二种:接口Mapper.xml(需要重复配置)
34             第三种:第二种升级版,扫描方式自动加载Dao接口Mapper,不用一个一个的配置,扫描的包
35                 注意事项:Dao接口和Mapper文件在同一目录下(包下),并且UserDao.java UserDao.xml 同名
36         -->    
37         <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
38             <property name="basePackage" value="cn.itcast.core.dao"/>
39         </bean>
40         
41 </beans>
View Code

properties.xml: 读取属性文件

技术分享
 1 <beans xmlns="http://www.springframework.org/schema/beans"
 2     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
 3     xmlns:context="http://www.springframework.org/schema/context"
 4     xmlns:aop="http://www.springframework.org/schema/aop" 
 5     xmlns:tx="http://www.springframework.org/schema/tx"
 6     xmlns:task="http://www.springframework.org/schema/task"
 7     xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
 8     xsi:schemaLocation="http://www.springframework.org/schema/beans 
 9         http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
10         http://www.springframework.org/schema/mvc 
11         http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
12         http://www.springframework.org/schema/context 
13         http://www.springframework.org/schema/context/spring-context-4.0.xsd 
14         http://www.springframework.org/schema/aop 
15         http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
16         http://www.springframework.org/schema/tx 
17         http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
18         http://www.springframework.org/schema/task
19            http://www.springframework.org/schema/task/spring-task-4.0.xsd
20         http://code.alibabatech.com/schema/dubbo        
21         http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
22         
23         <!-- 读取properties文件 -->
24         <!-- <context:property-placeholder location="classpath:jdbc.properties"/> -->
25         <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
26             <property name="locations">
27                 <list>
28                     <value>classpath:jdbc.properties</value>
29                 </list>
30             </property>
31         </bean>
32         
33 </beans>
View Code

transaction.xml:事务配置文件

技术分享
 1 <beans xmlns="http://www.springframework.org/schema/beans"
 2     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
 3     xmlns:context="http://www.springframework.org/schema/context"
 4     xmlns:aop="http://www.springframework.org/schema/aop" 
 5     xmlns:tx="http://www.springframework.org/schema/tx"
 6     xmlns:task="http://www.springframework.org/schema/task"
 7     xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
 8     xsi:schemaLocation="http://www.springframework.org/schema/beans 
 9         http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
10         http://www.springframework.org/schema/mvc 
11         http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
12         http://www.springframework.org/schema/context 
13         http://www.springframework.org/schema/context/spring-context-4.0.xsd 
14         http://www.springframework.org/schema/aop 
15         http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
16         http://www.springframework.org/schema/tx 
17         http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
18         http://www.springframework.org/schema/task
19            http://www.springframework.org/schema/task/spring-task-4.0.xsd
20         http://code.alibabatech.com/schema/dubbo        
21         http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
22         
23         <!-- 配置事务-->
24         <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
25             <property name="dataSource" ref="dataSource"></property>
26         </bean>
27         
28         <!-- @Transaction 开启事务注解 -->
29         <tx:annotation-driven transaction-manager="transactionManager"/>
30         
31 </beans>
View Code


6, 整合Spring

Login/Console/Portal 都是输入Controller层, 所以这三个project都需要做此配置.
这里以Console为例子:
先看一下Console project整体目录结构:
技术分享

web.xml:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
 5     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 6     
 7     <!-- 前端控制器 -->
 8     <servlet>
 9         <servlet-name>console</servlet-name>
10         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
11         <init-param>
12             <param-name>contextConfigLocation</param-name>
13             <!-- 默认读取的是 WEB-INF/console-servlet.xml -->
14             <param-value>classpath:springmvc-console.xml</param-value>
15         </init-param>
16     </servlet>
17     
18     <servlet-mapping>
19         <servlet-name>console</servlet-name>
20         <!-- 
21             /*: 拦截视图请求: .jsp  .js  .css  几乎不用,配置静态资源过滤
22             /: 拦截所有,不拦截.jsp 文件, 但是同样拦截.js .css  如果使用也需要配置静态资源过滤(前台系统使用)
23             *.do:拦截所有以.do请求, 后台开发应用*.do
24          -->
25         <url-pattern>*.do</url-pattern>
26     </servlet-mapping>
27 </web-app>


springmvc-console.xml:Springmvc配置文件

技术分享
 1 <beans xmlns="http://www.springframework.org/schema/beans"
 2     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
 3     xmlns:context="http://www.springframework.org/schema/context"
 4     xmlns:aop="http://www.springframework.org/schema/aop" 
 5     xmlns:tx="http://www.springframework.org/schema/tx"
 6     xmlns:task="http://www.springframework.org/schema/task"
 7     xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
 8     xsi:schemaLocation="http://www.springframework.org/schema/beans 
 9         http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
10         http://www.springframework.org/schema/mvc 
11         http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
12         http://www.springframework.org/schema/context 
13         http://www.springframework.org/schema/context/spring-context-4.0.xsd 
14         http://www.springframework.org/schema/aop 
15         http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
16         http://www.springframework.org/schema/tx 
17         http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
18         http://www.springframework.org/schema/task
19            http://www.springframework.org/schema/task/spring-task-4.0.xsd
20         http://code.alibabatech.com/schema/dubbo        
21         http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
22         
23     <!-- 扫描@Controller -->
24     <context:component-scan base-package="cn.itcast"/>
25         
26     <!-- 处理器适配器 映射器 -->
27     <mvc:annotation-driven/>
28     
29     <!-- jsp视图解析器 -->
30     <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
31         <property name="prefix" value="/WEB-INF/console/"/>
32         <property name="suffix" value=".jsp"/>
33     </bean>
34     
35     <import resource="dubbo-customer.xml"/>
36         
37 </beans>
View Code


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

[项目构建]babasport SSM 三大框架整合 [练手项目]

标签:

原文地址:http://www.cnblogs.com/wang-meng/p/5777797.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!