spring+mybatis配置
整合mybatis到spring中,需要用到mybatis-spring-1.1.1.jar
其他spring相关的jar包,可以在mybatis-spring-1.1.1-bundle.zip中找到
mybatis-spring-1.1.1-bundle.zip可以在mybatis官网的MyBatis Integration下载到最新版本
?
spring中,mybatis的配置如下:
<!-- define the SqlSessionFactory --><bean id="sqlSessionFactory" ref="c3p0" /><!-- ORM映射文件 --><property name="configLocation" value="classpath:/config/ibatis/mybatis-config.xml" /><!--<property name="mapperLocations" value="classpath:/hr/dao/ibatis/maps/**/*Mapper.xml" />--> <!--<property name="typeAliasesPackage" value="com.tes.bean" />--> </bean><!-- sqlMapper与Mapper.xml映射 --><bean value="hr.dao.ibatis.sqlMapper" /></bean>
?
mybatis-config.xml的配置如下:
<configuration><!-- 属性配置 --><properties /><!-- 设置缓存和延迟加载等等重要的运行时的行为方式 --><settings><!-- 设置超时时间,它决定驱动等待一个数据库响应的时间 --><setting name="defaultStatementTimeout" value="25000"/></settings><!-- 别名 --><typeAliases/><!-- 使用MapperScannerConfigurer就可以不用手动配置mappers了 mybatis会根据basePackage的值,自动去扫描 (如果mappers文件过多,32位JDK扫描会很慢,64位JDK没有问题) <mappers> <mapper resource="org/mybatis/example/BlogMapper.xml"/> </mappers>--></configuration>
?
?