1.异常分析

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

大概意思就是:在只读模式(FlushMode.MANUAL)中不允许写操作,将您的会话转换为FlushMode.COMMIT/AUTO或从事务定义中删除“readOnly”标记。

2.分析原因:

<1>.事务通知相应方法设置属性,read-only="true"

  <tx:advice id="txadvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>

此时dao层只可以执行,get,find,count(*)等查询操作,不可以执行cud 操作

<2>.事务通知了相应方法添加事务,但是aop管理设置时切入点表达式却不包含该方法 ,则其read-only 默认为 true

<!-- txadvice设置 --> 
<tx:advice id="txadvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="*" read-only="false"/>
</tx:attributes>
</tx:advice>
<!--aop管理设置--> <aop:config>
<aop:pointcut expression="execution(* com.ssj..*.*())" id="myPointcut"/>//注意此处*.*()括号中为无参
<aop:advisor advice-ref="txadvice" pointcut-ref="myPointcut"/>
</aop:config>

注意:此处事务通知了所有方法添加事务,而切入点却只拦截了无参的方法.也就是说此时只有无参的构造方法是

可以进行cud操作的,而有参的则不能.

<3>.使用注解配置事务的时注解忘记添加也会抛出此异常

<4>.使用扫描添加注解的时候导致覆盖

例如:applicationContext.xml中com.ssj扫描全局添加注解之后,

  在springmvc.xml中又扫描一次com,ssj导致将applicationContext配置的事务覆盖,而且此配置文件中并没有相关事务的配置.从而出现此种异常

3.解决方案

针对原因一:将method 中read-only设置为false即可

针对原因二:将切入点表达式完善为:execution(* com.ssj..*.*(..)) 即可

针对原因三:在需要加事务的类上添加语句:

@Transactional(isolation=Isolation.DEFAULT,propagation=Propagation.REQUIRED)

 注:在使用Spring代理时,默认只有在public可见度的方法的@Transactional 注解才是有效的,

  其它可见度(protected、private、包可见)的方法上即使有@Transactional 注解也不会应用这些事务属性的,Spring也不会报错,

  如果你非要使用非公共方法注解事务管理的话,可考虑使用AspectJ。

针对原因四:在springmvc.xml中配置扫描范围的时候不要涉及到applicationContext.xml中配置的事务设置范围

例如: applicationContext--->"execution(* com.ssj.service..*.*(..))" 给service包中的方法添加事务通知   注:使用@transaction注解时,同样

   springmvc.xml------><context:component-scan base-package="com.ssj.controller"></context:component-scan>

           开启注解扫描的时候不要涉及到service包中的方法,只管理controller即可

spring整合问题分析之-Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.的更多相关文章

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

    Struts Problem Report Struts has detected an unhandled exception: Messages: Write operations are not ...

  2. spring整合之后运行报什么只读错误。Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.

    解决办法, 再大dao的实现类上添加注解: @Transactional(readOnly = false ) 不让它只读就行了

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

    这个错误我整理了  半天才发现问题的存在. 尝试了网上的很多办法,但是最后都没有达到效果. 包括这两种: 第一种: web.xml种的配置 <filter> <filter-name ...

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

    如果在service类上面没有添加注解,出现异常 @Transactional

  5. 增删改查 报异常org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readO

    可能是Spring配置文件 事务通知里面的方法  与实际方法不匹配 <tx:advice id="advice" transaction-manager="tran ...

  6. ssh整合思想 Spring分模块开发 crud参数传递 解决HTTP Status 500 - Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or(增加事务)

    在Spring核心配置文件中没有增加事务方法,导致以上问题 Action类UserAction package com.swift.action; import com.opensymphony.xw ...

  7. Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnl

    org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read ...

  8. Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn

    这个异常我在网上查看了很多资料,一般都说是hibernate的session问题,让重新两个方法,但是我以前用的时候没问题啊,所以一直找问题,终于这个bug让我找到了,就是因为我插入操作的时候用的是别 ...

  9. hibernate+spring整合增删改事务错误

    org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read ...

随机推荐

  1. CSU 1329: 一行盒子

    1329: 一行盒子 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 740  Solved: 145[Submit][Status][Web Board ...

  2. C++忽略字符大小写比较

    在项目中用到对两个字符串进行忽略大小写的比较,有两个方法实现 1.使用C++提供的忽略大小写比较函数实现 代码实现: /* 功能 :忽略大小写进行字符串比较 */ #ifdef __LINUX__ # ...

  3. Activiti(一)--安装配置具体解释

    有一段时间没有更新文章了,尽管有一直在写文章,但是一直没有更新到博客内,这段时间写的文章大多还是以技术为主. 接下来的系列文章将会来讨论企业工作流的开发,主要是来研究开源工作流Activiti的使用. ...

  4. Python List 中 Append 和 Extent 方法不返回值。

    Append: list的append 方法是没有返回值的,因此list 的引用L被置为空 结果也就自然是空了. 再看一个例子: append 跟extend方法的区别是什么呢? 其实这样看的就很清楚 ...

  5. C++11 中function和bind以及lambda 表达式的用法

    关于std::function 的用法:  其实就可以理解成函数指针 1. 保存自由函数 void printA(int a) { cout<<a<<endl; } std:: ...

  6. Github上fork项目后与原项目保持同步

    **步骤** 假设来源为 `https://github.com/_original/_project.git` fork 项目为  `https://github.com/_your/_projec ...

  7. TPM--Trusted Platform Module

    trouSerS是IBM的一帮牛人搞的TSS软件栈,提供了与TPM交互的API,从而可以让我们方便地编写应用程序. 地址:https://sourceforge.net/projects/trouse ...

  8. nginx中,$request_uri和$uri的区别

    nginx中,$request_uri和$uri的区别   $request_uri This variable is equal to the *original* request URI as r ...

  9. 【Mac + Appium + Python3.6学习(五)】之常用的Android自动化测试API总结

    Github测试样例地址:https://github.com/appium-boneyard/sample-code/tree/master/sample-code/examples ①定位text ...

  10. JVM性能调优监控工具专题一:JVM自带性能调优工具(jps,jstack,jmap,jhat,jstat,hprof)

    性能分析工具jstatjmapjhatjstack 前提概要:         JDK本身提供了很多方便的JVM性能调优监控工具,除了集成式的VisualVM和jConsole外,还有jps.jsta ...