前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Spring3整合Ibatis3配置

Spring3整合Ibatis3配置

作者头像
py3study
发布2020-01-06 16:52:03
3270
发布2020-01-06 16:52:03
举报
文章被收录于专栏:python3python3python3

步骤一:在web.xml中配置spring

<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:spring/applicationContext*.xml</param-value> </context-param>     <!--Spring的ApplicationContext 载入 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>

步骤二:配置applicationContext.xml

<!--设置配置文件-->

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath*:/application.properties</value> <value>classpath*:/db.properties</value> </list> </property> </bean>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="maxActive" value="20" /> <property name="maxIdle" value="20" /> <property name="maxWait" value="3000" /> <property name="testWhileIdle" value="true" /> <property name="timeBetweenEvictionRunsMillis" value="3600000" /> <property name="validationQuery" value="select 1" /> <property name="removeAbandoned" value="true" /> <property name="removeAbandonedTimeout" value="1" /> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> </bean>

<bean id="sqlSessionFactory" class="org.springframework.orm.ibatis3.SqlSessionFactoryBean"> <property name="configLocation" value="classpath:ibatis-config.xml" /> <property name="dataSource" ref="dataSource" /> </bean> <bean id="sqlSessionTemplate" class="org.springframework.orm.ibatis3.SqlSessionTemplate"> <property name="sqlSessionFactory" ref="sqlSessionFactory" /> </bean>   <!--事务配置--> <tx:annotation-driven transaction-manager="transactionManager" /> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" autowire="byName" />

注:db.properties内容如下

jdbcNum=2 jdbc.driverClass=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://192.168.1.1:3306/bookdb?useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false jdbc.username=sophie jdbc.passworld=123456

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-09-22 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档