JSP 中spring事務(wù)配置詳解
JSP 中spring事務(wù)配置詳解
前幾天被問(wèn)到,如何防止服務(wù)器宕機(jī),造成的數(shù)據(jù)操作的不完全。
問(wèn)了一下同事,是事務(wù)。哎,恍然大悟,迷糊一時(shí)了。
聲明式的事務(wù)配置,這個(gè)是最推薦的,配置到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自動(dòng)注冊(cè)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"/> <!-- 檢查數(shù)據(jù)庫(kù)連接池中空閑連接的間隔時(shí)間 --> <property name="idleConnectionTestPeriod" value="4" /> <!-- 連接池中未使用的鏈接最大存活時(shí)間 --> <property name="idleMaxAge" value="240" /> <!-- 設(shè)置每個(gè)分區(qū)含有connection最大個(gè)數(shù) --> <property name="maxConnectionsPerPartition" value="20" /> <!-- 設(shè)置每個(gè)分區(qū)含有connection最小個(gè)數(shù) --> <property name="minConnectionsPerPartition" value="10" /> <!-- 設(shè)置每個(gè)分區(qū)數(shù) --> <property name="partitionCount" value="3" /> <!-- 設(shè)置分區(qū)中的connection增長(zhǎng)數(shù)量 --> <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>
其中,有個(gè)通配符是有點(diǎn)問(wèn)題的。事務(wù)在于更新數(shù)據(jù)時(shí)候使用,查詢(xún)不需要事務(wù)。所以直接用* ,這樣太過(guò)于暴力了。
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
相關(guān)文章
jsp自定義標(biāo)簽技術(shù)(實(shí)現(xiàn)原理與代碼以及平臺(tái)搭建步驟)
由于jsp代碼規(guī)范要求不能出現(xiàn)一句java代碼。所有就有了jsp 的自定義標(biāo)簽技術(shù)2013-06-06使用maven+eclipse搭建struts2開(kāi)發(fā)環(huán)境
Struts 2是Apache基金會(huì)的明星級(jí)產(chǎn)品,提供了對(duì)MVC的一個(gè)清晰的實(shí)現(xiàn),下面就為大家介紹一下使用maven+eclipse搭建struts2開(kāi)發(fā)環(huán)境的方法2014-01-01使用JSP制作一個(gè)超簡(jiǎn)單的網(wǎng)頁(yè)計(jì)算器的實(shí)例分享
這篇文章主要介紹了一個(gè)使用JSP制作超簡(jiǎn)單的網(wǎng)頁(yè)計(jì)算器的實(shí)例,文中的方法利用到了JavaBean組件,需要的朋友可以參考下2016-04-04讓JSP頁(yè)面過(guò)期, 保證每次JSP頁(yè)面都是最新的.
讓JSP頁(yè)面過(guò)期, 保證每次JSP頁(yè)面都是最新的....2006-10-10關(guān)于JSP的一點(diǎn)疑問(wèn)小結(jié)
我在做一個(gè)JSP小測(cè)試.寫(xiě)的一些代碼如下2009-02-02