隨筆 - 6  文章 - 129  trackbacks - 0
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(14)

          隨筆檔案(6)

          文章分類(467)

          文章檔案(423)

          相冊

          收藏夾(18)

          JAVA

          搜索

          •  

          積分與排名

          • 積分 - 827222
          • 排名 - 49

          最新評論

          閱讀排行榜

          評論排行榜

          Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.

          今天在做事務測試的時候,控制臺輸出了以上的錯誤信息,在網上找了一下,原來是我在web.xml
          文件中設置了OpenSessionInView .  將設置去掉就可以了.
          <!-- OpenSessionInView -->
            <filter>
             <filter-name>OpenSessionInViewFilter</filter-name>
             <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
            </filter>
            <filter-mapping>
             <filter-name>OpenSessionInViewFilter</filter-name>
             <url-pattern>*.action</url-pattern>
            </filter-mapping>
          或者加上事務設置

          <?xml version="1.0" encoding="UTF-8"?>
          <beans
           xmlns="http://www.springframework.org/schema/beans"
           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-2.0.xsd
           http://www.springframework.org/schema/tx
              http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
              http://www.springframework.org/schema/aop
              http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"
           >
           <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory" ref="sessionFactory"></property>
           </bean>
           
           <tx:advice id="txAdvice" transaction-manager="transactionManager">
            <tx:attributes>
             <tx:method name="create*" propagation="REQUIRED"/>
             <tx:method name="update*" propagation="REQUIRED"/>
             <tx:method name="delete*" propagation="REQUIRED"/>
             <tx:method name="find*" propagation="REQUIRED" read-only="true"/>
             <tx:method name="*" read-only="true"/>
            </tx:attributes>
           </tx:advice>
           
           <aop:config>
            <aop:pointcut id="daoOperation" expression="execution(* dgut.ke.dao.*.*(..))"/>
            <aop:advisor advice-ref="txAdvice" pointcut-ref="daoOperation"/>
           </aop:config>
           
          </beans>

          網上又說
          盡管Open Session In View看起來還不錯,其實副作用不少。看回上面OpenSessionInViewFilter的doFilterInternal方法代碼,這個方法實際上是被父類的doFilter調用的,因此,我們可以大約了解的OpenSessionInViewFilter調用流程: request(請求)->open session并開始transaction->controller->View(Jsp)->結束transaction并close session.

               一切看起來很正確,尤其是在本地開發測試的時候沒出現問題,但試想下如果流程中的某一步被阻塞的話,那在這期間connection就一直被占用而不釋放。最有可能被阻塞的就是在寫Jsp這步,一方面可能是頁面內容大,response.write的時間長,另一方面可能是網速慢,服務器與用戶間傳輸時間久。當大量這樣的情況出現時,就有連接池連接不足,造成頁面假死現象。

          Open Session In View是個雙刃劍,放在公網上內容多流量大的網站請慎用。




          posted on 2007-11-16 16:51 Ke 閱讀(1952) 評論(0)  編輯  收藏 所屬分類: exception
          主站蜘蛛池模板: 台前县| 揭阳市| 二手房| 临朐县| 囊谦县| 会理县| 隆化县| 闽清县| 察雅县| 于田县| 平和县| 来安县| 石城县| 通城县| 丹巴县| 澄城县| 米脂县| 称多县| 内江市| 宜良县| 平江县| 漳浦县| 黎城县| 景宁| 台湾省| 文安县| 墨竹工卡县| 修文县| 高安市| 巴林左旗| 宜兰市| 云霄县| 定西市| 金湖县| 四会市| 万州区| 广西| 平顺县| 许昌县| 华坪县| 武威市|