SSM框架的搭建完整步骤.docx
《SSM框架的搭建完整步骤.docx》由会员分享,可在线阅读,更多相关《SSM框架的搭建完整步骤.docx(18页珍藏版)》请在冰豆网上搜索。
SSM框架的搭建完整步骤
SSM框架的搭建
一、新建javaweb项目,并建好相应的包结构
二、添加项目jar到lib目录下
三、在config包中新建配置文件
sping-mvc.xml,内容如下:
xmlversion="1.0"encoding="UTF-8"?
>
//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"
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-4.0.xsd
http:
//www.springframework.org/schema/mvc
http:
//www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
--注解扫描包-->
component-scanbase-package="com.hyg.im"/>
--开启注解-->
annotation-driven/>
spring-common.xml内容如下:
xmlversion="1.0"encoding="UTF-8"?
>
//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:
tx="http:
//www.springframework.org/schema/tx"
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/tx
http:
//www.springframework.org/schema/tx/spring-tx-4.0.xsd">
--1.数据源:
DriverManagerDataSource-->
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
mysql:
//localhost:
3306/test"/>
--
2.mybatis的SqlSession的工厂:
SqlSessionFactoryBeandataSource:
引用数据源
MyBatis定义数据源,同意加载配置
-->
--
3.mybatis自动扫描加载Sql映射文件/接口:
MapperScannerConfigurersqlSessionFactory
basePackage:
指定sql映射文件/接口所在的包(自动扫描)
-->
--
4.事务管理:
DataSourceTransactionManagerdataSource:
引用上面定义的数据源
-->
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
--5.使用声明式事务
transaction-manager:
引用上面定义的事务管理器
-->
annotation-driventransaction-manager="txManager"/>
四、配置web.xml,内容如下:
xmlversion="1.0"encoding="UTF-8"?
>
xmlns:
xsi="http:
//www.w3.org/2001/XMLSchema-instance"
xsi:
schemaLocation="
--加载Spring容器配置-->
org.springframework.web.context.ContextLoaderListener
--设置Spring容器加载所有的配置文件的路径-->
contextConfigLocation
classpath*:
config/spring-*.xml
--配置SpringMVC核心控制器-->
springMVC
org.springframework.web.servlet.DispatcherServlet
--配置初始配置化文件,前面contextConfigLocation看情况二选一-->
contextConfigLocation
classpath*:
config/spring-mvc.xml
--启动加载一次-->
1
--为DispatcherServlet建立映射-->
springMVC
--此处可以可以配置成*.do,对应struts的后缀习惯-->
/
default
*.html
default
*.gif
default
*.css
default
*.js
default
*.jpg
default
*.png
--防止Spring内存溢出监听器-->
org.springframework.web.util.IntrospectorCleanupListener<