In the spring configuration file, configure the bean corresponding to the transaction template class
<!--manual Transaction template--
<bean id= "transactiontemplate" class= " Org.springframework.transaction.support.TransactionTemplate ">
<property name=" TransactionManager "ref= "Txmgr"/>
</bean>
Using the transaction template in service, manually rollback the current transaction where a transaction rollback is required, as shown in the following code:
Message msg = Transactiontemplate.execute (new transactioncallback<message> () {
@Override
public Message dointransaction (transactionstatus status) {
message returnmsg = new Message ();
try {
returnmsg = debitinfoservice.domoddebitinfowhenprocessfinish (requestmap);
if (!returnmsg.issuccess ()) {
status.setrollbackonly ();
}
} catch (Exception e) {
Returnmsg.setsuccess (false);
Returnmsg.setmsg (Exceptionutils.getmessage (e));
Returnmsg.setvalue (Exceptionutils.getstacktrace (e));
Status.setrollbackonly ();
}
return returnmsg;
}
});
If processing errors, log if
(!msg.issuccess ()) {
loggerutil.error ("Debit Return", Msg.getmsg (), Msg.getvalue ());
}
if (msg.issuccess ()) {
resultmap.put ("status", "1");
} else{
resultmap.put ("status", "0");
}