import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallbackWithoutResult; public class AnonymousClassExample { private static final Integer f = 1; private void sentNotificationResultEventInTransaction() { new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { f.toString(); } }; } }