SSM框架整合.docx

上传人:b****3 文档编号:3746203 上传时间:2022-11-25 格式:DOCX 页数:21 大小:137.26KB
下载 相关 举报
SSM框架整合.docx_第1页
第1页 / 共21页
SSM框架整合.docx_第2页
第2页 / 共21页
SSM框架整合.docx_第3页
第3页 / 共21页
SSM框架整合.docx_第4页
第4页 / 共21页
SSM框架整合.docx_第5页
第5页 / 共21页
点击查看更多>>
下载资源
资源描述

SSM框架整合.docx

《SSM框架整合.docx》由会员分享,可在线阅读,更多相关《SSM框架整合.docx(21页珍藏版)》请在冰豆网上搜索。

SSM框架整合.docx

SSM框架整合

SSM框架整合

1、整合准备

整合内容:

整合架构:

Spring、SpringMVC以及MyBatis的整合。

数据库:

MySQL

连接池:

Druid(阿里巴巴研发)

整合工具:

整合工具为:

Eclipse

Jar管理工具:

Maven

项目类型为:

MavenPproject

2、SSM整合

2.1、导入整合相关的jar包(Maven)

pom.xml文件

//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.0http:

//maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

com.woo0nise

woo0nise-parent

0.0.1-SNAPSHOT

SSM

SSM

0.0.1-SNAPSHOT

war

--MySql-->

mysql

mysql-connector-java

--连接池-->

com.alibaba

druid

--Spring-->

--spring核心包-->

org.springframework

spring-core

org.springframework

spring-context

org.springframework

spring-beans

org.springframework

spring-web

--Spring对JDBC的封装-->

org.springframework

spring-jdbc

org.springframework

spring-aspects

--关系型数据库整合时需配置如hibernatejpa等-->

org.springframework

spring-orm

--SpringMVC核心-->

org.springframework

spring-webmvc

--JacksonJson处理工具包(非必须)-->

com.fasterxml.jackson.core

jackson-databind

--单元测试-->

junit

junit

test

--日志处理(非必须)-->

org.slf4j

slf4j-log4j12

--Mybatis-->

org.mybatis

mybatis

--mybatis的整合包-->

org.mybatis

mybatis-spring

--mybatis分页插件(非必须)-->

com.github.pagehelper

pagehelper

com.github.miemiedev

mybatis-paginator

--JSP相关-->

jstl

jstl

javax.servlet

servlet-api

provided

javax.servlet

jsp-api

provided

--如果不添加此节点mybatis的mapper.xml文件都会被漏掉。

-->

src/main/java

**/*.properties

**/*.xml

false

2.2、创建整合目录

Mybatis:

存放mybatis配置文件

Spring:

存放spring以及整合文件

Resource:

数据库连接以及log4配置信息

2.3、创建MyBatis配置文件

创建mybatis-config.xml文件位于mybatis目录下

mybatis-config.xml

xmlversion="1.0"encoding="UTF-8"?

>

DOCTYPEconfiguration

PUBLIC"-//mybatis.org//DTDConfig3.0//EN"

"http:

//mybatis.org/dtd/mybatis-3-config.dtd">

该文件主要存mybatis配置。

(该配置文件可以不创建)

2.4、创建数据库配置信息

创建db.properties文件位于resource文件夹下

db.properties

#数据库连接驱动

jdbc.driver=com.mysql.jdbc.Driver

#数据库连接url

jdbc.url=jdbc:

mysql:

//localhost:

3306/woo0nise?

characterEncoding=utf-8

#数据库用户名

jdbc.username=root

#数据库密码

jdbc.password=root

该配置文件主要存放数据库的配置,也可以存放mybatis配置文件的属性。

2.5、Spring整合mybatis

创建applicationContext-dao.xml文件位于spring文件夹下

applicationContext-dao.xml

xmlversion="1.0"encoding="UTF-8"?

>

//www.springframework.org/schema/beans"

xmlns:

xsi="http:

//www.w3.org/2001/XMLSchema-instance"

xmlns:

aop="http:

//www.springframework.org/schema/aop"

xmlns:

context="http:

//www.springframework.org/schema/context"

xmlns:

jdbc="http:

//www.springframework.org/schema/jdbc"

xmlns:

p="http:

//www.springframework.org/schema/p"

xmlns:

tx="http:

//www.springframework.org/schema/tx"

xmlns:

util="http:

//www.springframework.org/schema/util"

xsi:

schemaLocation="http:

//www.springframework.org/schema/beanshttp:

//www.springframework.org/schema/beans/spring-beans.xsd

http:

//www.springframework.org/schema/aophttp:

//www.springframework.org/schema/aop/spring-aop-4.1.xsd

http:

//www.springframework.org/schema/contexthttp:

//www.springframework.org/schema/context/spring-context-4.1.xsd

http:

//www.springframework.org/schema/jdbchttp:

//www.springframework.org/schema/jdbc/spring-jdbc-4.1.xsd

http:

//www.springframework.org/schema/txhttp:

//www.springframework.org/schema/tx/spring-tx-4.1.xsd

http:

//www.springframework.org/schema/utilhttp:

//www.springframework.org/schema/util/spring-util-4.1.xsd">

--加载数据库配置文件-->

property-placeholderlocation="classpath:

resource/db.properties"/>

--配置数据源-->

--数据库连接池-->

destroy-method="close">

--配置SqlSessionFactory-->

--配置数据源-->

--配置MyBatis路径-->

mybatis/mybatis-config.xml">

--Mapper文件扫描器-->

该配置文件主要是spring整合mybatis文件。

2.6、Spring事务管理

创建applicationContext-trans.xml位于spring文件夹下

applicationContext-trans.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:

jdbc="http:

//www.springframework.org/schema/jdbc"

xmlns:

p="http:

//www.springframework.org/schema/p"

xmlns:

tx="http:

//www.springframework.org/schema/tx"

xmlns:

util="http:

//www.springframework.org/schema/util"

xmlns:

aop="http:

//www.springframework.org/schema/aop"

xsi:

schemaLocation="http:

//www.springframework.org/schema/jdbchttp:

//www.springframework.org/schema/jdbc/spring-jdbc-4.1.xsd

http:

//www.springframework.org/schema/beanshttp:

//www.springframework.org/schema/beans/spring-beans.xsd

http:

//www.springframework.org/schema/contexthttp:

//www.springframework.org/schema/context/spring-context-4.1.xsd

http:

//www.springframework.org/schema/aophttp:

//www.springframework.org/schema/aop/spring-aop-4.1.xsd

http:

//www.springframework.org/schema/txhttp:

//www.springframework.org/schema/tx/spring-tx-4.1.xsd

http:

//www.springframework.org/schema/utilhttp:

//www.springframework.org/schema/util/spring-util-4.1.xsd">

--配置事务管理器-->

--配置数据源-->

--配置事务-->

adviceid="txAdvice"transaction-manager="transactionManager">

attributes>

methodname="save*"propagation="REQUIRED"/>

methodname="insert*"propagation="REQUIRED"/>

methodname="add*"propagation="REQUIRED"/>

methodname="create*"propagation="REQUIRED"/>

methodname="delete*"propagation="REQUIRED"/>

methodname="update*"propagation="REQUIRED"/>

methodname="find*"propagation="SUPPORTS"read-only="true"/>

methodname="select*"propagation="SUPPORTS"read-only="true"/>

methodname="get*"propagation="SUPPORTS"read-only="true"/>

attributes>

advice>

--切面-->

config>

advisoradvice-ref="txAdvice"

pointcut="execution(*com.taotao.service.impl.*.*(..))"/>

config>

该配置文件主要配置事务以及事务管理和切面(AOP)配置。

2.7、Spring扫描Service的实现类

创建applicationContext-service.xml位于spring文件夹下

applicationContext-service-xml

xmlversion="1.0"encoding="UTF-8"?

>

//www.springframework.org/schema/beans"

xmlns:

xsi="http:

//www.w3.org/2001/XMLSchema-instance"

xmlns:

aop="http:

//www.springframework.org/schema/aop"

xmlns:

context="http:

//www.springframework.org/schema/context"

xmlns:

jdbc="http:

//www.springframework.org/schema/jdbc"

xmlns:

p="http:

//www.springframework.org/schema/p"

xmlns:

tx="http:

//www.springframework.org/schema/tx"

xmlns:

util="http:

//www.springframework.org/schema/util"

xsi:

schemaLocation="http:

//www.springframework.org/schema/beanshttp:

//www.springframework.org/schema/beans/spring-beans.xsd

http:

//www.springframework.org/schema/aophttp:

//www.springframework.org/schema/aop/spring-aop-4.1.xsd

http:

//www.springframework.org/schema/contexthttp:

//www.springframework.org/schema/context/spring-context-4.1.xsd

http:

//www.springframework.org/schema/jdbchttp:

//www.springframework.org/schema/jdbc/spring-jdbc-4.1

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 农林牧渔 > 水产渔业

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1