SSM框架整合的其它方式

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

  

  

  

  

  

  

  

  

SSM 框架整合的其它方式

  

  

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

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

  

  

  

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

核心配置文件中

  

  

  

3、具体实现

  

applicationContext.xml:

  

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

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">

 

 

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

 

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

 

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

 

name="locations">

classpath:jdbc.properties

 

 

 

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

 

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

 

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

 

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

 

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

 

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

 

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

 

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

 

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

 

 

 

 

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

 

name="dataSource"ref="dataSource"/>

 

name="configuration">

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

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

 

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

  

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

 

 

 

 

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

name="userMapper"ref="userMapper">

 

 

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

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

 

 

 

 

id="transactionManager"

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

name="dataSource"ref="dataSource"/>

  

transaction-manager="transactionManager"/>

 

  

  

  

  

注:主要针对sqlSessionFactoryBean 做修改

  

  

  

  

  

  

  

【made by siwuxie095】

你可能感兴趣的:(SSM框架)