濮阳杆衣贸易有限公司

主頁 > 知識庫 > JSP 中spring事務(wù)配置詳解

JSP 中spring事務(wù)配置詳解

熱門標(biāo)簽:南京新思維電話機器人 企業(yè)怎么在聯(lián)通申請400電話 如何用中國地圖標(biāo)注數(shù)字點 好操作的電話機器人廠家 南昌市地圖標(biāo)注app 泰州泰興400電話 怎么申請 地圖標(biāo)注市場怎么樣 聊城智能電銷機器人外呼 百度地圖添加標(biāo)注圖標(biāo)樣式

JSP 中spring事務(wù)配置詳解

前幾天被問到,如何防止服務(wù)器宕機,造成的數(shù)據(jù)操作的不完全。

問了一下同事,是事務(wù)。哎,恍然大悟,迷糊一時了。

聲明式的事務(wù)配置,這個是最推薦的,配置到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=truecharacterEncoding=utf8"/>
    property name="username" value="root"/>
    property name="password" value="123456"/>

    !-- 檢查數(shù)據(jù)庫連接池中空閑連接的間隔時間 -->
    property name="idleConnectionTestPeriod" value="4" />
    !-- 連接池中未使用的鏈接最大存活時間 -->
    property name="idleMaxAge" value="240" />
    !-- 設(shè)置每個分區(qū)含有connection最大個數(shù) -->
    property name="maxConnectionsPerPartition" value="20" />
    !-- 設(shè)置每個分區(qū)含有connection最小個數(shù) -->
    property name="minConnectionsPerPartition" value="10" />
    !-- 設(shè)置每個分區(qū)數(shù) -->
    property name="partitionCount" value="3" />
    !-- 設(shè)置分區(qū)中的connection增長數(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>

其中,有個通配符是有點問題的。事務(wù)在于更新數(shù)據(jù)時候使用,查詢不需要事務(wù)。所以直接用* ,這樣太過于暴力了。

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

您可能感興趣的文章:
  • JSP 獲取spring容器中bean的兩種方法總結(jié)
  • JSP開發(fā)中在spring mvc項目中實現(xiàn)登錄賬號單瀏覽器登錄
  • Spring boot 跳轉(zhuǎn)到j(luò)sp頁面的實現(xiàn)方法
  • SpringBoot創(chuàng)建JSP登錄頁面功能實例代碼
  • java實現(xiàn)圖片上加文字水?。⊿pringMVC + Jsp)
  • JSP 獲取Spring 注入對象示例
  • JSP spring boot / cloud 使用filter防止XSS

標(biāo)簽:白銀 自貢 吉林 臨汾 銅川 開封 烏蘭察布 山南

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《JSP 中spring事務(wù)配置詳解》,本文關(guān)鍵詞  JSP,中,spring,事務(wù),配置,詳解,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《JSP 中spring事務(wù)配置詳解》相關(guān)的同類信息!
  • 本頁收集關(guān)于JSP 中spring事務(wù)配置詳解的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    保山市| 贡山| 益阳市| 合水县| 大竹县| 淮阳县| 平度市| 柳河县| 泾川县| 自治县| 蒙城县| 军事| 合山市| 永靖县| 高平市| 东乡县| 万州区| 三江| 邮箱| 乐平市| 苍梧县| 社旗县| 阳新县| 连州市| 新宁县| 万载县| 湖州市| 大港区| 云阳县| 临邑县| 烟台市| 苏尼特右旗| 土默特右旗| 东丽区| 夹江县| 山西省| 贺州市| 天镇县| 高淳县| 寿宁县| 渑池县|