spring 2.5整合jdbc進行資料庫操作和XML事務控制

來源:互聯網
上載者:User

 

1:將上一篇的註解配置jdbc整合的業務介面的實作類別裡面的註解都去掉

2:修改設定檔如下:

  <?xml version="1.0" encoding="UTF-8"?><br /><beans xmlns="http://www.springframework.org/schema/beans"<br /> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"<br /> xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"<br /> xsi:schemaLocation=" </p><p>http://www.springframework.org/schema/beans</p><p>http://www.springframework.org/schema/beans/spring-beans-2.5.xsd</p><p>http://www.springframework.org/schema/context</p><p>http://www.springframework.org/schema/context/spring-context-2.5.xsd</p><p>http://www.springframework.org/schema/aop</p><p>http://www.springframework.org/schema/aop/spring-aop-2.5.xsd</p><p>http://www.springframework.org/schema/tx</p><p> http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"><br /><context:property-placeholder location="classpath:jdbc.properties" /></p><p><bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"><br /> <property name="driverClassName" value="${jdbc.driverClassName}"></property><br /> <property name="url" value="${jdbc.url}"></property><br /> <property name="username" value="${jdbc.username}"></property><br /> <property name="password" value="${jdbc.password}"></property><br /> <!-- 串連池啟動時的初始值,一般兩三條就夠了 --><br /> <property name="initialSize" value="${jdbc.initialSize}"></property><br /> <!-- 串連池的最大值 --><br /> <property name="maxActive" value="${jdbc.maxActive}"></property><br /> <!-- 最大空閑值,當經過一個高峰時間後,串連池可以慢慢將用不到的串連釋放一部分,一直減少到maxIdle為止 --><br /> <property name="maxIdle" value="${jdbc.maxIdle}"></property><br /> <!-- 最小空閑值,當閒置串連數小於閥值時,串連池就會預申請一些串連,以免峰值到時來不及申請--><br /> <property name="minIdle" value="${jdbc.minIdle}"></property><br /> </bean><br /> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><br /> <property name="dataSource" ref="dataSource"></property><br /> </bean><br /> <aop:config><br /> <aop:pointcut id="transactionPointcut" expression_r="execution(* service.imp..*(..))"/><br /> <aop:advisor advice-ref="txAdvice" pointcut-ref="transactionPointcut"/><br /> </aop:config><br /> <tx:advice id="txAdvice" transaction-manager="transactionManager" ><br /> <tx:attributes><br /> <tx:method name="get*" read-only="true" propagation="NOT_SUPPORTED"/><br /> <tx:method name="*"/><br /> </tx:attributes><br /> </tx:advice><br /><bean id="suService" class="service.imp.SuServiceImpl"><br /><property name="dataSource" ref="dataSource"></property><br /></bean><br /></beans></p><p>

到此結束。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.