[Java] Using annotation in spring simultaneously marks JMS + database transactions

Source: Internet
Author: User

I am not proficient in spring. During the two days of resolving JMS exceptions, I found that jmstrasactionmanager is provided in spring and transaction management interfaces are also implemented. In this way, you can use an automatic Interceptor to automatically control transactions like databases. It is valid when both JMS and database transactions are configured. In this way, the system message and database transaction will be lightweight and consistent!

For spring configuration for the database, see: http://steeven.cnblogs.com/archive/2005/06/14/174410.html
The JMS section is as follows:

< Bean ID = "Remotejmsconnectionfactory"
Class
= "Org. activemq. activemqconnectionfactory" >
< Property Name = "Useembeddedbroker" >
< Value > True </ Value >
</ Property >
< Property Name = "Brokerurl" >
< Value > TCP: // localhost: 61616 </ Value >
</ Property >
</ Bean >

< Bean ID = "Jmstm"
Class
= "Org. springframework. JMS. Connection. jmstransactionmanager" >
< Property Name = "Connectionfactory" >
< Ref Bean = "Remotejmsconnectionfactory"   />
</ Property >
</ Bean >

< Bean ID = "Jmstransactioninterceptor"
Class
= "Org. springframework. transaction. Interceptor. transactioninterceptor" >
< Property Name = "Transactionmanager" >
< Ref Bean = "Jmstm"   />
</ Property >
< Property Name = "Transactionattributesource" >
< Bean
Class = "Org. springframework. transaction. annotation. annotationtransactionattributesource"   />
</ Property >
</ Bean >

< Bean
Class = "Org. springframework. transaction. Interceptor. transactionattributesourceadvisor" >
< Property Name = "Transactioninterceptor" >
< Ref Bean = "Jmstransactioninterceptor"   />
</ Property >
</ Bean >

< Bean ID = "Destresolver"
Class
= "Test. Message. enumdestinationresolver"   />

<! -- For send JMS to remote server -->
< Bean ID = "Remotejmstemplate"
Class
= "Org. springframework. JMS. Core. jmstemplate" >
< Property Name = "Connectionfactory" >
< Ref Bean = "Remotejmsconnectionfactory"   />
</ Property >
< Property Name = "Destinationresolver" >
< Ref Local = "Destresolver"   />
</ Property >
</ Bean >

Application Program Simple
@ Transactional
Public   Class Testserviceimpl implements testservice {
Public VoidSomemethod (){
Getjmstemplate (). Send (somemessage );
}

}

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.