---------------------siwuxie095

 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 

SSM 框架整合的其它方式

 
 

 
 

1、主要是整合
Spring 框架和 MyBatis 框架时,可以不写

MyBatis 核心配置文件:mybatis-config.xml

 
 

 
 

 
 

2、把
MyBatis 核心配置文件中的配置全都转移到
Spring

核心配置文件中

 
 

 
 

 
 

3、具体实现

 
 

applicationContext.xml:

 
 

<?xml
version="1.0"
encoding="UTF-8"?>

<beans
xmlns="http://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: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/aop

http://www.springframework.org/schema/aop/spring-aop.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx.xsd">

 

 

<!-- 使用spring自带的占位符替换功能 -->

<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

 

<!-- 允许JVM参数覆盖 -->

<property
name="systemPropertiesModeName"
value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>

 

<!-- 忽略没有找到的资源文件 -->

<property
name="ignoreResourceNotFound"
value="true"/>

 

<!-- 配置资源文件(也称
外部属性文件) -->

<property
name="locations">

<list>

<value>classpath:jdbc.properties</value>

</list>

</property>

 

</bean>

 

 

<!-- 配置 BoneCP 连接池 -->

<bean
id="dataSource"
class="com.jolbox.bonecp.BoneCPDataSource"
destroy-method="close">

 

<!-- 数据库驱动 -->

<property
name="driverClass"
value="${jdbc.driverClassName}"
/>

 

<!-- 相应驱动的jdbcUrl -->

<property
name="jdbcUrl"
value="${jdbc.url}"
/>

 

<!-- 数据库的用户名 -->

<property
name="username"
value="${jdbc.username}"
/>

 

<!-- 数据库的密码 -->

<property
name="password"
value="${jdbc.password}"
/>

 

,如果要取消则设置为0 -->

<property
name="idleConnectionTestPeriod"
value="60"
/>

 

,如果要永远存活设置为0 -->

<property
name="idleMaxAge"
value="30"
/>

 

<!-- 每个分区最大的连接数 -->

<property
name="maxConnectionsPerPartition"
value="150"
/>

 

<!-- 每个分区最小的连接数 -->

<property
name="minConnectionsPerPartition"
value="5"
/>

 

</bean>

 

 

 

<!-- 将 SqlSessionFactory 对象的创建交给 Spring 进行管理 -->

<bean
id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">

 

<!-- 指定数据源 -->

<property
name="dataSource"
ref="dataSource"
/>

 

<!-- 开启自动驼峰命名规则映射 -->

<property
name="configuration">

<bean
class="org.apache.ibatis.session.Configuration">

<property
name="mapUnderscoreToCamelCase"
value="true"/>

</bean>

</property>

 

<!-- 指定 MyBatis 映射配置文件的位置(路径) -->

<property
name="mapperLocations"
value="classpath:com/siwuxie095/mapper/*.xml"/>

 
 

<!-- 指定
类型别名的扫描包 -->

<property
name="typeAliasesPackage"
value="com.siwuxie095.entity"/>

 

</bean>

 

 

 

<!-- 配置 Service 对象 -->

<bean
id="userService"
class="com.siwuxie095.service.UserService">

<property
name="userMapper"
ref="userMapper"></property>

</bean>

 

 

<!-- 配置映射器接口(Mapper 接口)的扫描包 -->

<bean
class="org.mybatis.spring.mapper.MapperScannerConfigurer">

<!-- 如有多个包,以逗号

分号隔开即可 -->

<property
name="basePackage"
value="com.siwuxie095.mapper"/>

</bean>

 

 

<!--

配置映射器接口(以下方法二选一即可,这里选择法二):

 

法一:逐个配置:配置映射器接口(Mapper 接口)的对象

 

<bean id="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">

<property name="mapperInterface" value="com.siwuxie095.mapper.UserMapper"/>

<property name="sqlSessionFactory" ref="sqlSessionFactory"/>

</bean>

 

 

法二:统一配置:配置映射器接口(Mapper 接口)的扫描包

 

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">

<property name="basePackage" value="com.siwuxie095.mapper"/>

</bean>

 

-->

 

 

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

<bean
id="transactionManager"

class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

<!-- 注入 dataSource -->

<property
name="dataSource"
ref="dataSource"
/>

</bean>

 
 

<!-- 配置事务注解,即
开启事务注解 -->

<tx:annotation-driven
transaction-manager="transactionManager"/>

 

<!-- 一般事务管理都是在 Service 层进行,只需在 Service 类上加上 @Transactional 注解 -->

 
 

 
 

</beans>

 
 

 
 

注:主要针对
sqlSessionFactory

Bean 做修改

 
 

 
 

 
 

 
 

 
 

 
 

 
 

【made by siwuxie095】

SSM框架整合的其它方式的更多相关文章

  1. SSM框架整合项目 :租房管理系统

    使用ssm框架整合,oracle数据库 框架: Spring SpringMVC MyBatis 导包: 1, spring 2, MyBatis 3, mybatis-spring 4, fastj ...

  2. SSM框架整合环境构建——基于Spring4和Mybatis3

    目录 环境 配置说明 所需jar包 配置db.properties 配置log4j.properties 配置spring.xml 配置mybatis-spring.xml 配置springmvc.x ...

  3. springmvc(二) ssm框架整合的各种配置

    ssm:springmvc.spring.mybatis这三个框架的整合,有耐心一步步走. --WH 一.SSM框架整合 1.1.整合思路 从底层整合起,也就是先整合mybatis与spring,然后 ...

  4. SSM框架整合过程总结

    -----------------------siwuxie095                                 SSM 框架整合过程总结         1.导入相关 jar 包( ...

  5. 使用IntelliJ IDEA创建Maven聚合工程、创建resources文件夹、ssm框架整合、项目运行一体化

    一.创建一个空的项目作为存放整个项目的路径 1.选择 File——>new——>Project ——>Empty Project 2.WorkspaceforTest为项目存放文件夹 ...

  6. SSM框架整合(实现从数据库到页面展示)

    SSM框架整合(实现从数据库到页面展示) 首先创建一个spring-web项目,然后需要配置环境dtd文件的引入,环境配置,jar包引入. 首先让我来看一下ssm的基本项目配件.(代码实现) 1.首先 ...

  7. JAVAEE——宜立方商城01:电商行业的背景、商城系统架构、后台工程搭建、SSM框架整合

    1. 学习计划 第一天: 1.电商行业的背景. 2.宜立方商城的系统架构 a) 功能介绍 b) 架构讲解 3.工程搭建-后台工程 a) 使用maven搭建工程 b) 使用maven的tomcat插件启 ...

  8. SpringMVC札集(10)——SSM框架整合

    自定义View系列教程00–推翻自己和过往,重学自定义View 自定义View系列教程01–常用工具介绍 自定义View系列教程02–onMeasure源码详尽分析 自定义View系列教程03–onL ...

  9. (转)淘淘商城系列——SSM框架整合之Dao层整合

    http://blog.csdn.net/yerenyuan_pku/article/details/72721093 一个项目中往往有三层即Dao层.Service层和Web层,看标题就知道了,本文 ...

随机推荐

  1. 内存或磁盘空间不足 Microsoft Excel无法再次打开解决方法

    在网络上下载的文件,使用EXCEL打开的时候提示“内存或磁盘空间不足,Microsoft Excel 无法再次打开或保存任何文档.”,针对这个问题,装机之家小编特地在网上搜罗了具体解决方法,但是网上提 ...

  2. alias重命名命令

    升级了openssh后,发现ctrl+l忽然无法清屏了. 如果需要清屏的话,就得执行clear,但我更喜欢简单粗暴的做法,于是想起alias命令 方式一: 如果只想在当前终端生效(exit该窗口终端后 ...

  3. ajax 调用webservice 跨域问题

    注意两点 1. 在webservice的config中加入这段位置 (注意不是调用webservice的webconfig中加入) <system.webServer>     <! ...

  4. k8s中yaml文件pod的语法(转)

    kubernetes yaml格式的Pod配置文件 # yaml格式的pod定义文件完整内容: apiVersion: v1 #必选,版本号,例如v1 kind: Pod #必选,Pod metada ...

  5. 汉语言处理工具pyhanlp的拼音转换与字符正则化

    汉字转拼音 HanLP中的汉字转拼音功能也十分的强大. 说明: l HanLP不仅支持基础的汉字转拼音,还支持声母.韵母.音调.音标和输入法首字母首声母功能. l HanLP能够识别多音字,也能给繁体 ...

  6. Spring Boot - 基础 POM 文件

    表 1. Spring Boot 推荐的基础 POM 文件 名称 说明 spring-boot-starter 核心 POM,包含自动配置支持.日志库和对 YAML 配置文件的支持. spring-b ...

  7. [zz] 拍照需谨慎:20张错位照片让人笑喷

    http://www.kaixin001.com/qiushi/repaste/105876543_10386791939.html?uid=130103872&urpid=103957489 ...

  8. 问题 Windows7VMware14安装虚拟机时出现 此主机不支持虚拟化实际模式。需要具备 Intel“VMX 不受限客户机”功能才能在 Intel 处理器上运行此虚拟机。 模块“CPUIDEarly”启动失败。

    问题 Windows7VMware14安装虚拟机时出现 此主机不支持虚拟化实际模式.需要具备 Intel“VMX 不受限客户机”功能才能在 Intel 处理器上运行此虚拟机. 模块“CPUIDEarl ...

  9. flutter环境配置

    java环境安装 做基于android的原生app,首先需要安装java环境,需要到官网https://www.oracle.com/technetwork/java/javase/downloads ...

  10. centos7升级Python2.x到3.x

    CentOS 7 中默认安装了 Python,版本比较低(2.7.5),为了使用新版 3.x,需要对旧版本进行升级.由于很多基本的命令.软件包都依赖旧版本,比如:yum.所以,在更新 Python 时 ...