• <i id='Dayyp'><tr id='Dayyp'><dt id='Dayyp'><q id='Dayyp'><span id='Dayyp'><b id='Dayyp'><form id='Dayyp'><ins id='Dayyp'></ins><ul id='Dayyp'></ul><sub id='Dayyp'></sub></form><legend id='Dayyp'></legend><bdo id='Dayyp'><pre id='Dayyp'><center id='Dayyp'></center></pre></bdo></b><th id='Dayyp'></th></span></q></dt></tr></i><div id='Dayyp'><tfoot id='Dayyp'></tfoot><dl id='Dayyp'><fieldset id='Dayyp'></fieldset></dl></div>
      <legend id='Dayyp'><style id='Dayyp'><dir id='Dayyp'><q id='Dayyp'></q></dir></style></legend>
    1. <small id='Dayyp'></small><noframes id='Dayyp'>

        • <bdo id='Dayyp'></bdo><ul id='Dayyp'></ul>
        <tfoot id='Dayyp'></tfoot>

      1. 我应该将@Transactional 注释放在哪里:在接口定义或

        时间:2023-07-26
        <i id='aooXF'><tr id='aooXF'><dt id='aooXF'><q id='aooXF'><span id='aooXF'><b id='aooXF'><form id='aooXF'><ins id='aooXF'></ins><ul id='aooXF'></ul><sub id='aooXF'></sub></form><legend id='aooXF'></legend><bdo id='aooXF'><pre id='aooXF'><center id='aooXF'></center></pre></bdo></b><th id='aooXF'></th></span></q></dt></tr></i><div id='aooXF'><tfoot id='aooXF'></tfoot><dl id='aooXF'><fieldset id='aooXF'></fieldset></dl></div>
          <bdo id='aooXF'></bdo><ul id='aooXF'></ul>

          1. <legend id='aooXF'><style id='aooXF'><dir id='aooXF'><q id='aooXF'></q></dir></style></legend>

                <tfoot id='aooXF'></tfoot>
                  <tbody id='aooXF'></tbody>

                  <small id='aooXF'></small><noframes id='aooXF'>

                • 本文介绍了我应该将@Transactional 注释放在哪里:在接口定义或实现类中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  代码中标题的问题:

                  @Transactional (readonly = true)
                  public interface FooService {
                     void doSmth ();
                  }
                  
                  
                  public class FooServiceImpl implements FooService {
                     ...
                  }
                  

                  public interface FooService {
                     void doSmth ();
                  }
                  
                  @Transactional (readonly = true)
                  public class FooServiceImpl implements FooService {
                     ...
                  }
                  

                  推荐答案

                  来自 http://static.springsource.org/spring/docs/2.0.x/reference/transaction.html

                  Spring 团队的建议是您只使用 @Transactional 注释来注释具体类,而不是注释接口.您当然可以将 @Transactional接口(或接口方法)上的 注释,但这只会在您使用基于接口的代理时按预期工作.注释不被继承这一事实意味着,如果您使用基于类的代理,则基于类的代理基础设施将无法识别事务设置,并且对象不会被包装在事务代理中(这绝对是糟糕).所以请务必听取 Spring 团队的建议,只使用 @Transactional 注释来注释具体类(以及具体类的方法).

                  The Spring team's recommendation is that you only annotate concrete classes with the @Transactional annotation, as opposed to annotating interfaces. You certainly can place the @Transactional annotation on an interface (or an interface method), but this will only work as you would expect it to if you are using interface-based proxies. The fact that annotations are not inherited means that if you are using class-based proxies then the transaction settings will not be recognised by the class-based proxying infrastructure and the object will not be wrapped in a transactional proxy (which would be decidedly bad). So please do take the Spring team's advice and only annotate concrete classes (and the methods of concrete classes) with the @Transactional annotation.

                  注意:由于这种机制是基于代理的,只有通过代理传入的外部"方法调用才会被拦截.这意味着自调用",即目标内的方法对象调用目标对象的某些其他方法,即使调用的方法标有 @Transactional!

                  Note: Since this mechanism is based on proxies, only 'external' method calls coming in through the proxy will be intercepted. This means that 'self-invocation', i.e. a method within the target object calling some other method of the target object, won't lead to an actual transaction at runtime even if the invoked method is marked with @Transactional!

                  (在第一句中添加了重点,原文中的其他重点.)

                  (Emphasis added to the first sentence, other emphasis from the original.)

                  这篇关于我应该将@Transactional 注释放在哪里:在接口定义或实现类中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:像 @Override 这样的注解在 Java 内部是如何工作的 下一篇:如何编写 Java 注释处理器?

                  相关文章

                  最新文章

                • <small id='IlN7O'></small><noframes id='IlN7O'>

                  <tfoot id='IlN7O'></tfoot>
                    <bdo id='IlN7O'></bdo><ul id='IlN7O'></ul>
                  <i id='IlN7O'><tr id='IlN7O'><dt id='IlN7O'><q id='IlN7O'><span id='IlN7O'><b id='IlN7O'><form id='IlN7O'><ins id='IlN7O'></ins><ul id='IlN7O'></ul><sub id='IlN7O'></sub></form><legend id='IlN7O'></legend><bdo id='IlN7O'><pre id='IlN7O'><center id='IlN7O'></center></pre></bdo></b><th id='IlN7O'></th></span></q></dt></tr></i><div id='IlN7O'><tfoot id='IlN7O'></tfoot><dl id='IlN7O'><fieldset id='IlN7O'></fieldset></dl></div>

                      <legend id='IlN7O'><style id='IlN7O'><dir id='IlN7O'><q id='IlN7O'></q></dir></style></legend>