Mybatis整合Spring的配置文件样例
来源:互联网 发布:休闲单机游戏推荐知乎 编辑:程序博客网 时间:2024/06/06 09:14
<?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>
阅读全文
0 0
- Mybatis整合Spring的配置文件样例
- spring整合mybatis的配置文件
- spring-mybatis整合(配置文件)
- mybatis整合spring配置文件
- spring整合mybatis的applicationContext.xml配置文件
- Spring+SpringMVC+MyBatis整合配置文件的搭建
- Spring与Mybatis整合配置文件
- struts2 + spring + mybatis 整合配置文件
- spring与mybatis整合配置文件
- mybatis与spring整合配置文件
- spring mybatis整合读取配置文件
- spring+springmvc+mybatis整合配置文件
- 关于Spring与mybatis整合无法读取配置文件的问题
- 浅谈spring+springMVC+mybatis框架整合(配置文件的使用)
- Spring ,Springmvc,mybatis三大框架整合的配置文件支持
- spring 整合mybatis 出现解析不了配置文件的问题
- SSM整合(三) -- Spring和Mybatis的配置文件详解
- 整合SpringMVC+Spring+Mybatis+mysql的maven配置文件pom.xml
- Hibernate关于一对多 多对一 多对多关联关系的设置
- JVM
- 《UNIX网络编程 卷1》 笔记: 非阻塞式connect—web客户程序
- 第13周作业1(LeetCode20)
- LNMP 源码安装
- Mybatis整合Spring的配置文件样例
- Linux源码安装LAMP
- Candece疑惑
- windows系统提示不是内部或外部命令也不是可运行的程序的解决办法
- 变量自增的陷阱
- 机器学习算法工程师需要掌握的技能
- 计蒜客 腾讯狼人杀 简单 状压+枚举
- Chrome浏览器如何运行扩展程序?
- 重定向和转发