Ответ 1
Существуют различные стратегии распространения транзакций. Они существуют в перечислении Propagation
. Те, которые вы хотите использовать, - это
/**
* 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() {...}
}
Здесь вы можете найти все стратегии распространения .