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 );
}
}