`
月亮不懂夜的黑
  • 浏览: 151278 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Spring内异常 application exception overridden by commit exception

阅读更多

在执行某一操作时,意外发现自己定义的异常,无法被外面的Controller catch到。

追查发现在service内是可以正常打印异常信息,但外层Controller仅能拿到一个事务回滚的roolback异常。

仔细查看错误信息:

 

application exception overridden by commit exception

 应用自定义异常被事务异常覆盖了。

 

那么如何正常的在外层捕获到自定义的异常呢?

方法1.在对应的service上追加

@Transactional(rollbackFor = DemoException.class)

方法2.让自定义的异常继承RuntimeException(未校验,不过理论上是可以的)

 

那么为什么会可以呢?

事情的原因是 only unchecked exceptions cause rollbacks in spring transactions.(Spring的默认回滚RuntimeException)

在Spring事务管理里仅会回滚非检查异常。

我们捕获了一些特殊的情况,处理完之后会自动转化为一个checked exception 。事务不会对该异常做回滚。后续的事务回滚会覆盖自定义的异常。

 

0
0
分享到:
评论

相关推荐

    spring-dubbo-spring-boot.rar_java编程_spring_spring boot_threwwab_

    用于测试spring dubbo功能,提供对spring boot的支持

    javafx-8u152-apidocs-api

    public abstract class Application extends Object Application class from which JavaFX applications extend. Life-cycle The entry point for JavaFX applications is the Application class. The JavaFX ...

    微软内部资料-SQL性能优化3

    Application A lock resource defined by an application. The lock manager knows nothing about the resource format. It simply compares the 'strings' representing the lock resources to determine whether ...

    Making Use of Python (2002).pdf

    Identify the Methods to Be Overridden 173 Write the Code 182 Execute the Code 189 Summary 190 Chapter 9 Exception Handling 193 Getting Started 193 Handling Exceptions 194 Identify the Type of ...

    VC帮助文档

    Public and protected class members are documented only when they are normally used in application programs or derived classes. Occasionally, private members are listed because they override a public ...

    vitualTreeview的英文手册

    retrieved from the application via events (or descendants via overridden methods). Virtual Treeview has been carefully designed and thoroughly tested. The control proved its concept as well as ...

    servlet2.4doc

    Notification that the web application initialization process is starting. Cookie - class javax.servlet.http.Cookie. Creates a cookie, a small amount of information sent by a servlet to a Web browser,...

    USB短信猫驱动

    The device can be installed with ResetPipeRequestRetryCount set to any value by changing FTDIBUS.INF as shown in the following fragment. [FtdiBus_AddService.AddReg] HKR,Parameters,"RetryResetCount",...

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    - FIX: In the method TFlexPanel.ResizeSelection exception occurred when the number of selected items changed while the method was running. - ADD: Added the method TFlexControl.DoNeedHint - allows ...

    Delphi7.1 Update

    * Setting MTSDataModule.AutoComplete to False in the IDE is overridden and set back to True at run time (Quality Central 4716).* Calls to ApplyUpdates(-1) on a TMTSDataModule do not work properly ...

    vp_color_table.rar_esprit_lynx prime_objects_vertex array

    The color tracking is enabled so that our material diffuse colors are overridden by our vertex colors. To do this we ll enable the "All Geometries Lit" and "Use Material Diffuse Color" options in the...

    CSS优化工具CSSO.zip

    Removal of overridden shorthand properties Removal of repeating selectors Partial merging of blocks Partial splitting of blocks Removal of empty ruleset and at-rule Minification of margin ...

    ansible-role-oh-my-zsh:安装和配置oh-my-zsh的角色

    Ansible角色:我的Zsh 负责下载,安装和配置 。 注意:使用备用角色可能会更好,该角色可以安装第三方Zsh插件以及安装Oh My...# May be overridden by `oh_my_zsh: install:` under each user. oh_my_zsh_install : y

    louie:jekyll主题(看起来很棒)

    路易 jekyll投资组合生成器(看起来很棒)。 Louie是免费,轻量级的,并且可以自定义为博客,档案或投资组合。 安装 将此行添加到您的Jekyll网站的Gemfile中: ..., which is overridden by post/page title if exists

    VirtualTreeView V5.5

    Everything is retrieved from the application via events (or descendants via overridden methods). Virtual Treeview has been carefully designed and thoroughly tested. The control proved its concept ...

    休斯顿:Apple Push Notifications; 不需要飞船

    推送通知不一定很困难。 休斯顿是发送Apple Push Notifications的简单工具。 传递您的凭据,构造您的消息,然后发送。...# Environment variables are automatically read, or can be overridden by any specified op

    xfrog.dlo for 3DS MAX 4.2, 5.0, 6.0

    made to the mesh itself will be overridden when the object is reevaluated. Options Panel ------------------------------------------------- The Animation Length Group lets you choose between the ...

    elixir-navigation-tree:带有帮助程序的导航树表示形式,用于从中生成HTML-取决于用户角色-源码

    术语node :如下所示的配置结构: %NavigationTree.Node{ name: string, # the node's name, like "About Us" url: nil or string, # will be set on startup, but may be overridden controller: nil or string, # ...

    php.ini-development

    special sections cannot be overridden by user-defined INI files or ; at runtime. Currently, [PATH=] and [HOST=] sections only work under ; CGI/FastCGI. ; http://php.net/ini.sections ; Directives are...

    java教程课件4类的说明符

    为了确保某个函数的行为在继承过程中保持不变,并且不能被覆盖(overridden),可以使用final方法。

Global site tag (gtag.js) - Google Analytics