【Spring】XML配置整合Mybatis
2016-12-17 21:55
453 查看
注意:项目开发使用了mybatis的mapper代理!
首先是mybatis自己的配置文件,被spring整合之后,只有typeAliases存在了,其他都整合在了spring-mybatis.xml:
spring-mybatis整合xml:最后一个映射扫描做的很棒,把mapper接口都实例化了,并且实例名就是接口名
首先是mybatis自己的配置文件,被spring整合之后,只有typeAliases存在了,其他都整合在了spring-mybatis.xml:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- 类型别名 --> <typeAliases> <package name="com.z.model"/> </typeAliases> </configuration>
spring-mybatis整合xml:最后一个映射扫描做的很棒,把mapper接口都实例化了,并且实例名就是接口名
<?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:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> <!-- 引入属性文件 --> <context:property-placeholder location="classpath:config.properties" /> <!-- 配置数据源 使用了阿里的数据源配置 druid--> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <!-- 初始化连接大小 --> <property name="initialSize" value="0" /> <!-- 连接池最大使用连接数量 --> <property name="maxActive" value="20" /> <!-- 连接池最大空闲 --> <property name="maxIdle" value="20" /> <!-- 连接池最小空闲 --> <property name="minIdle" value="0" /> <!-- 获取连接最大等待时间 --> <property name="maxWait" value="60000" /> <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --> <property name="timeBetweenEvictionRunsMillis" value="60000" /> <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --> <property name="minEvictableIdleTimeMillis" value="25200000" /> <!-- 打开removeAbandoned功能 --> <property name="removeAbandoned" value="true" /> <!-- 1800秒,也就是30分钟 --> <property name="removeAbandonedTimeout" value="1800" /> <!-- 关闭abandoned连接时输出错误日志 --> <property name="logAbandoned" value="true" /> <!-- 监控数据库 --> <property name="filters" value="log4j" /> </bean> <!-- 会话工厂 based on dataSource --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 加载mybatis配置文件 --> <property name="configLocation" value="classpath:mybatis.xml"/> <property name="dataSource" ref="dataSource"/> </bean> <!-- 映射扫描 based on 会话工厂 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <!-- 指定扫描的包名 如果扫描多个包,每个包中间使用半角逗号分隔',', 不能使用通配符 --> <property name="basePackage" value="com.z.mapper"/> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/> </bean> </beans>
相关文章推荐
- Spring+Spring Mvc+Mybatis+MySqlite(SSM框架整合Xml配置)
- 整合SpringMVC+Spring+Mybatis+mysql的maven配置文件pom.xml
- spring和mybatis整合 sqlMapConfig.xml配置文件
- spring-mybatis整合xml配置
- spring、mybatis整合核心配置文件applicationContext.xml
- springMVC+MyBatis+meaven整合的pom.xml配置文件
- Spring+Mybatis整合配置xml
- mybatis-spring 的整合_配置application.xml
- spring+springMVC+mybatis整合示例(基于XML配置文件)
- MyBatis Spring整合配置映射接口类与映射xml文件
- SSM(spring-springmvc-mybatis)整合开发xml配置文件内容springmvc-config.xml,application.xml,web.xml
- MyBatis Spring整合配置映射接口类与映射xml文件
- Spring、MyBatis的整合数据映射器类(UserMapper->iocContext.xml)配置文件详解
- SSM Spring +SpringMVC+Mybatis 整合配置 及pom.xml
- spring和myBatis整合,springIOC.xml的配置文件
- springMVC+mybatis整合之applicationContext.xml基本配置详解
- springMVC+MyBatis+meaven整合的pom.xml配置文件
- spring+Mybatis+Ehcache整合(Ehcachec参数说明XML配置)
- spring-mybatis.xml配置文件,spring与mybatis整合在一起
- springboot整合mybatis注解版与XML配置版