注释类型 Transactional


  • @Target({TYPE,METHOD})
    @Retention(RUNTIME)
    @Inherited
    @Documented
    public @interface Transactional
    Describes a transaction attribute on an individual method or on a class.

    At the class level, this annotation applies as a default to all methods of the declaring class and its subclasses. Note that it does not apply to ancestor classes up the class hierarchy; methods need to be locally redeclared in order to participate in a subclass-level annotation.

    This annotation type is generally directly comparable to Spring's RuleBasedTransactionAttribute class, and in fact AnnotationTransactionAttributeSource will directly convert the data to the latter class, so that Spring's transaction support code does not have to know about annotations. If no custom rollback rules apply, the transaction will roll back on RuntimeException and Error but not on checked exceptions.

    For specific information about the semantics of this annotation's attributes, consult the TransactionDefinition and TransactionAttribute javadocs.

    This annotation commonly works with thread-bound transactions managed by PlatformTransactionManager, exposing a transaction to all data access operations within the current execution thread. Note: This does NOT propagate to newly started threads within the method.

    Alternatively, this annotation may demarcate a reactive transaction managed by ReactiveTransactionManager which uses the Reactor context instead of thread-local attributes. As a consequence, all participating data access operations need to execute within the same Reactor context in the same reactive pipeline.

    从以下版本开始:
    1.2
    作者:
    Colin Sampaleanu, Juergen Hoeller, Sam Brannen
    另请参阅:
    TransactionAttribute, DefaultTransactionAttribute, RuleBasedTransactionAttribute