1. 通过Maven创建一个javaWeb工程
src目录结构:
-main
-java
-controller
-entity
-dao
-service
-resource
-mapper
applicationContext.xml
log4j.properties
springmvc.xml
-webapp
-static
-WEB-INF
-view
web.xml
-test
2. 导入ssm框架所需jar包坐标
UTF-8
1.8
1.8
5.0.2.RELEASE
1.6.6
1.2.12
5.1.6
3.4.5
org.aspectj
aspectjweaver
1.6.8
org.springframework
spring-aop
${spring.version}
org.springframework
spring-context
${spring.version}
org.springframework
spring-web
${spring.version}
org.springframework
spring-webmvc
${spring.version}
org.springframework
spring-test
${spring.version}
org.springframework
spring-tx
${spring.version}
org.springframework
spring-jdbc
${spring.version}
junit
junit
4.12
test
mysql
mysql-connector-java
${mysql.version}
javax.servlet
servlet-api
2.5
provided
javax.servlet.jsp
jsp-api
2.0
provided
jstl
jstl
1.2
log4j
log4j
${log4j.version}
org.slf4j
slf4j-api
${slf4j.version}
org.slf4j
slf4j-log4j12
${slf4j.version}
org.mybatis
mybatis
${mybatis.version}
org.mybatis
mybatis-spring
1.3.0
com.alibaba
druid
1.0.15
compile
3. 搭建Spring框架环境
① 创建spring配置文件——applicationContext.xml
② 补全applicationContext.xml文件头约束条件
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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/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">
③ 开启注解扫描(dao+service)
4. 搭建SpringMVC环境
① 创建springMVC配置文件——springmvc.xml
② 补全springmvc.xml文件头约束条件
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
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.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
③ 开启注解扫描(controller)
④ 配置视图解析器
⑤ 配置过滤静态资源
⑤ 开启springMVC注解支持
⑥ 配置web.xml
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_4_0.xsd"
version="4.0">
Archetype Created Web Application
dispatcherServlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:springmvc.xml
1
dispatcherServlet
/
characterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
utf-8
characterEncodingFilter
/*
5. spring整合springMVC框架
web.xml文件中配置spring监听器
org.springframework.web.context.ContextLoaderListener
contextConfigLocation
classpath:applicationContext.xml
6. spring整合mybatis框架
位置:applicationContext.xml
① 配置连接池(druid)
② 配置SqlSessionFactory工厂
③ 配置dao接口所在的包
7. 配置spring事务管理
位置:applicationContext.xml
① 配置事务管理器
② 配置事务通知
③ 配置aop切点表达式