Mybatis整合Spring的配置文件样例
2017-05-27 23:25
405 查看
<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- 1.配置数据库相关参数的properties的属性-->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 2.数据库连接池-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!--配置连接池属性-->
<property name="driverClass" value="${driver}"/>
<property name="jdbcUrl" value="${url}"/>
<property name="user" value="${username}"/>
<property name="password" value="${password}"/>
<!--c3p0连接池的私有属性-->
<property name="maxPoolSize" value="30"/>
<property name="minPoolSize" value="10"/>
<!--关闭连接后不自动commit-->
<property name="autoCommitOnClose" value="false"/>
<!--获取连接超时时间-->
<property name="checkoutTimeout" value="1000"/>
<!--当获取连接失败重试次数-->
<property name="acquireRetryAttempts" value="2"/>
</bean>
<!--3.配置SqlSessionFactory对象-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!--注入数据库连接池-->
<property name="dataSource" ref="dataSource"/>
<!--配置MyBatis全局配置文件:mybatis-config.xml-->
<property name="configLocation" value="classpath:mybatis-config.xml"/>
<!--扫描entity包 使用别名-->
<property name="typeAlisesPackage" value="org.xxx.entity"/>
<!--扫描sql配置文件:mapper需要的xml文件-->
<property name="mapperLocation" value="classpath:xxx/*.xml"/>
</bean>
<!--4.配置扫描Dao接口包,动态实现Dao注入,注入到spring容器中-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--注入sqlSessionFactory-->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
<!--给出需要扫描Dao接口包-->
<property name="basePackage" value="org.xxx.dao"/>
</bean>
</beans>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- 1.配置数据库相关参数的properties的属性-->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 2.数据库连接池-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!--配置连接池属性-->
<property name="driverClass" value="${driver}"/>
<property name="jdbcUrl" value="${url}"/>
<property name="user" value="${username}"/>
<property name="password" value="${password}"/>
<!--c3p0连接池的私有属性-->
<property name="maxPoolSize" value="30"/>
<property name="minPoolSize" value="10"/>
<!--关闭连接后不自动commit-->
<property name="autoCommitOnClose" value="false"/>
<!--获取连接超时时间-->
<property name="checkoutTimeout" value="1000"/>
<!--当获取连接失败重试次数-->
<property name="acquireRetryAttempts" value="2"/>
</bean>
<!--3.配置SqlSessionFactory对象-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!--注入数据库连接池-->
<property name="dataSource" ref="dataSource"/>
<!--配置MyBatis全局配置文件:mybatis-config.xml-->
<property name="configLocation" value="classpath:mybatis-config.xml"/>
<!--扫描entity包 使用别名-->
<property name="typeAlisesPackage" value="org.xxx.entity"/>
<!--扫描sql配置文件:mapper需要的xml文件-->
<property name="mapperLocation" value="classpath:xxx/*.xml"/>
</bean>
<!--4.配置扫描Dao接口包,动态实现Dao注入,注入到spring容器中-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--注入sqlSessionFactory-->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
<!--给出需要扫描Dao接口包-->
<property name="basePackage" value="org.xxx.dao"/>
</bean>
</beans>
相关文章推荐
- spring与mybatis整合(基于配置文件)
- mybatis与spring整合(基于配置文件)(转)
- mybatis与spring整合(基于配置文件)
- Spring与Mybatis整合配置文件
- mybatis与spring整合(基于配置文件)
- mybatis与spring整合配置文件
- mybatis与spring整合(基于配置文件)
- spring-mybatis.xml配置文件,spring与mybatis整合在一起
- Spring、Spring MVC、MyBatis整合文件配置详解
- mybatis与spring整合(基于配置文件)
- Struts2 Spring3 Mybatis 3 整合 相关配置文件
- mybatis与spring整合(基于配置文件)
- mybatis与spring整合(基于配置文件)
- mybatis与spring整合(基于配置文件)
- struts2 + spring + mybatis 整合配置文件
- spring与mybatis整合配置文件
- SSM整合配置文件(Springmvc+Spring+Mybatis)
- Spring、MyBatis的整合数据映射器类(UserMapper->iocContext.xml)配置文件详解
- MyBatis和Spring整合配置文件笔记
- springmvc + spring + mybatis + maven整合配置文件