Spring3整合Ibatis3配置

步骤一:在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

本文出自 “我的JAVA之路” 博客,请务必保留此出处http://mmqzlj.blog.51cto.com/2092359/498975





本文来源于网络,仅代表作者观点,如果您是原作者,可联系我们删除本文

Spring3整合Ibatis3配置:等您坐沙发呢!

发表评论

Spam Protection by WP-SpamFree

快捷键:Ctrl+Enter