SPRINGMVC Configuration Transaction

Source: Internet
Author: User

1.SPRINGMVC configuring transactions, first configuring transactions in APPLICATION.XM

<!--configuration transaction manager-->
<bean id= "TransactionManager" class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager" >
<property name= "DataSource" ref= "DataSource"/>
</bean>

<tx:advice id= "Txadvice" transaction-manager= "TransactionManager" >
<tx:attributes>
<!--<tx:method name= "get*" read-only= "true" rollback-for= "Java.lang.Exception"/>-->
<tx:method name= "query*" read-only= "true"/>
<tx:method name= "select*" read-only= "true"/>
<tx:method name= "insert*" propagation= "REQUIRED" rollback-for= "Java.lang.Exception"/>
<!--<tx:method name= "*" rollback-for= "java.lang.Exception"/>--><!--default rollback mechanism is RuntimeException-->
</tx:attributes>
</tx:advice>

<aop:config>
<aop:pointcut id= "service" expression= "Execution" (* com.oracle.sx.businessData.service. *serviceimpl.* (..)) " /><!--Declare all methods of the class that contain the service to use the transaction-->
<aop:advisor advice-ref= "Txadvice" pointcut-ref= "service"/>
</aop:config>

2. In the corresponding*serviceimpl (Service implementation Class) The corresponding method adds an exception mechanism, as follows:

@Override
Public String adddept (Jsonobject obj) throws Exception {
Departmentinfo departmentinfo = new Departmentinfo ();
String RetCode = "";
String retmsg = "";
String objstr = "";
map<string, object> params = new hashmap<string, object> ();
Jsonobject jsonobject = new Jsonobject ();
try{
Business Block
}catch (Exception e) {
RetCode = Get_message_code. Unknown_error;
Retmsg = "Unknown error";
Log.info ("Interface exception information:" + e);
throw new Exception ();
}
Jsonobject.put ("response", retCode);
Jsonobject.put ("message", retmsg);
Convert JSON
Jsonarray Jsonarray = new Jsonarray ();
Jsonarray.add (Jsonobject);
Objstr = Jsonarray.tojsonstring ();
return objstr;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.