복붙노트

[SPRING] 전체 클래스의 트랜잭션 주석 + 단일 메소드 제외

SPRING

전체 클래스의 트랜잭션 주석 + 단일 메소드 제외

@Transactional 어노테이션이있는 클래스가 있습니다 (모든 메소드에 표시하는 대신).

@Transactional로 주석 처리해서는 안되는 클래스 내부에 단일 메서드가 있지만.

내 질문은 "비 트랜잭션"으로 표시하는이 메서드에 넣을 수있는 주석이 무엇입니까? 또는이 클래스의 각 단일 메서드를이 메서드를 제외한 "트랜잭션"로 표시해야합니다 (많은 작업)

감사.

해결법

  1. ==============================

    1.사용할 다른 트랜잭션 전파 전략이 있습니다. 이것들은 enum 전파에 존재합니다. 당신이 사용하기를 원하는 것들은

    사용할 다른 트랜잭션 전파 전략이 있습니다. 이것들은 enum 전파에 존재합니다. 당신이 사용하기를 원하는 것들은

    /**
     * Execute non-transactionally, suspend the current transaction if one exists.
     * Analogous to EJB transaction attribute of the same name.
     * <p>Note: Actual transaction suspension will not work on out-of-the-box
     * on all transaction managers. This in particular applies to JtaTransactionManager,
     * which requires the {@code javax.transaction.TransactionManager} to be
     * made available it to it (which is server-specific in standard J2EE).
     * @see org.springframework.transaction.jta.JtaTransactionManager#setTransactionManager
     */
    NOT_SUPPORTED(TransactionDefinition.PROPAGATION_NOT_SUPPORTED),
    
    /**
     * Execute non-transactionally, throw an exception if a transaction exists.
     * Analogous to EJB transaction attribute of the same name.
     */
    NEVER(TransactionDefinition.PROPAGATION_NEVER), // maybe not this one
    

    따라서 클래스 내부의 메소드에 이들 중 하나를 주석으로 표시하십시오.

    @Transactional
    public class MyTransactionalClass { 
        @Transactional(propagation = Propagation.NOT_SUPPORTED)
        public void nonTransactionalMethod() {...}
    }
    

    여기서 모든 전파 전략을 찾을 수 있습니다.

  2. from https://stackoverflow.com/questions/18233171/transactional-annotation-on-whole-class-excluding-a-single-method by cc-by-sa and MIT license