JSP 中spring事務配置詳解
更新時間:2017年05月02日 11:34:23 投稿:lqh
這篇文章主要介紹了JSP 中spring事務配置詳解的相關資料,需要的朋友可以參考下
JSP 中spring事務配置詳解
前幾天被問到,如何防止服務器宕機,造成的數據操作的不完全。
問了一下同事,是事務。哎,恍然大悟,迷糊一時了。
聲明式的事務配置,這個是最推薦的,配置到service層。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<!-- 使用annotation @Repository,@Service自動注冊bean, 并保證@Required、@Autowired的屬性被注入的包范圍 -->
<context:component-scan base-package="com.rd,com.rongdu"/>
<context:annotation-config/>
<bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
<!-- Connection Info -->
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/sfd?useUnicode=true&characterEncoding=utf8"/>
<property name="username" value="root"/>
<property name="password" value="123456"/>
<!-- 檢查數據庫連接池中空閑連接的間隔時間 -->
<property name="idleConnectionTestPeriod" value="4" />
<!-- 連接池中未使用的鏈接最大存活時間 -->
<property name="idleMaxAge" value="240" />
<!-- 設置每個分區(qū)含有connection最大個數 -->
<property name="maxConnectionsPerPartition" value="20" />
<!-- 設置每個分區(qū)含有connection最小個數 -->
<property name="minConnectionsPerPartition" value="10" />
<!-- 設置每個分區(qū)數 -->
<property name="partitionCount" value="3" />
<!-- 設置分區(qū)中的connection增長數量 -->
<property name="acquireIncrement" value="5" />
<property name="statementsCacheSize" value="50"/>
<property name="releaseHelperThreads" value="3"/>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
<bean id="namedParameterJdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
<constructor-arg index="0" ref="dataSource"/>
</bean>
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="allManagerMethod"
expression="execution(* com.test.service.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod" />
</aop:config>
</beans>
其中,有個通配符是有點問題的。事務在于更新數據時候使用,查詢不需要事務。所以直接用* ,這樣太過于暴力了。
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關文章
多種方法實現(xiàn)當jsp頁面完全加載完成后執(zhí)行一個js函數
實現(xiàn)jsp頁面完全加載完成后執(zhí)行一個js函數的方法有很多,在本文就簡單為大家介紹下常用的幾種,感興趣的朋友不要錯過2013-10-10
JSP 中response.setContentType()的作用及參數
這篇文章主要介紹了JSP 中response.setContentType()的作用及參數 的相關資料,希望通過本能幫助到大家,讓大家理解使用這部分內容,需要的朋友可以參考下2017-09-09
JSP實現(xiàn)從數據庫導出數據到Excel下載的方法
這篇文章主要介紹了JSP實現(xiàn)從數據庫導出數據到Excel下載的方法,涉及JSP操作excel文件導出的相關技巧,非常簡單實用,需要的朋友可以參考下2015-10-10
JSP使用Common FileUpload組件實現(xiàn)文件上傳及限制上傳類型實例代碼
這篇文章主要介紹了JSP使用Common FileUpload組件實現(xiàn)文件上傳及限制上傳類型實例代碼,需要的朋友可以參考下2017-09-09

