<context-param> <param-name>contextConfigLocat
ion
</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&characterEn
coding=utf8&autoReconnect=true&failOverReadOnly=false
jdbc.username=sophie
jdbc.passworld=123456
--结束END--
本文标题: Spring3整合Ibatis3配置
本文链接: https://lsjlt.com/news/191458.html(转载时请注明来源链接)
有问题或投稿请发送至:
邮箱/279061341@qq.com QQ/279061341
0