다음 코드의 newPrint
메서드는 새 트랜잭션을 만들어야하지만 분명히 oldPrint
메서드에서 사용 된 것과 동일한 트랜잭션 상태 개체를 출력합니다. oldPrint를 다른 클래스에서 호출하려고합니다. newPrint가 this
을 사용하여 호출 되었기 때문입니까? 그렇다면 새로운 거래가 언제 만들어 집니까? @Transactional
이 클래스 수준에서 사용되기 때문에 다른 클래스의 두 메서드를 모두 호출하면 별도의 두 트랜잭션이 만들어집니다.스프링 전파 .REQUIRES_NEW
@Transactional
public class Unsubcriber {
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public void newPrint() {
System.out.println(TransactionAspectSupport.currentTransactionStatus());
}
public void oldPrint() {
System.out.println(TransactionAspectSupport.currentTransactionStatus());
newPrint();
}
출력 : Propagation.REQUIRES_NEW
이 작동 할 때
o[email protected]3bacd0e7
o[email protected]3bacd0e7
어떤 시나리오가 될 것이다?
내부 oldPrint, 당신은'newPrint()'대신()'인쇄'의 의미합니까? – geoand
@geoand 내 나쁜, 그냥 내 질문을 편집했습니다. 감사! – Abidi
내 대답을 확인하십시오 :) – geoand