Remove non-batch JMS tests - so that AMQ only has one broker for the whole suite.
This commit is contained in:
@@ -5,9 +5,6 @@
|
||||
</configExtensions>
|
||||
<configs>
|
||||
<config>src/test/resources/org/springframework/batch/jms/jms-context.xml</config>
|
||||
<config>src/test/resources/org/springframework/jms/asynch.xml</config>
|
||||
<config>src/test/resources/org/springframework/jms/synch.xml</config>
|
||||
<config>src/test/resources/org/springframework/jms/tx.xml</config>
|
||||
<config>src/test/resources/data-source.xml</config>
|
||||
</configs>
|
||||
<configSets>
|
||||
@@ -17,7 +14,6 @@
|
||||
<incomplete>false</incomplete>
|
||||
<configs>
|
||||
<config>src/test/resources/data-source.xml</config>
|
||||
<config>src/test/resources/org/springframework/jms/synch.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
@@ -35,7 +31,6 @@
|
||||
<incomplete>false</incomplete>
|
||||
<configs>
|
||||
<config>src/test/resources/data-source.xml</config>
|
||||
<config>src/test/resources/org/springframework/jms/asynch.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
</configSets>
|
||||
|
||||
@@ -1,151 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.jms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.jms.listener.DefaultMessageListenerContainer;
|
||||
import org.springframework.jms.listener.SessionAwareMessageListener;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.TransactionCallback;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
public class AsynchronousTests extends AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { ClassUtils.classPackageAsResourcePath(getClass()) + "/asynch.xml" };
|
||||
}
|
||||
|
||||
private DefaultMessageListenerContainer container;
|
||||
|
||||
private JmsTemplate jmsTemplate;
|
||||
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
private PlatformTransactionManager transactionManager;
|
||||
|
||||
public void setTransactionManager(PlatformTransactionManager transactionManager) {
|
||||
this.transactionManager = transactionManager;
|
||||
}
|
||||
|
||||
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
public void setJmsTemplate(JmsTemplate jmsTemplate) {
|
||||
this.jmsTemplate = jmsTemplate;
|
||||
}
|
||||
|
||||
public void setContainer(DefaultMessageListenerContainer container) {
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
protected void onSetUp() throws Exception {
|
||||
super.onSetUp();
|
||||
String foo = "";
|
||||
int count = 0;
|
||||
while (foo != null && count < 100) {
|
||||
foo = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
count++;
|
||||
}
|
||||
jdbcTemplate.execute("delete from T_FOOS");
|
||||
jmsTemplate.convertAndSend("queue", "foo");
|
||||
}
|
||||
|
||||
protected void onTearDown() throws Exception {
|
||||
super.onTearDown();
|
||||
container.stop();
|
||||
// Need to give the container time to shutdown
|
||||
Thread.sleep(2000L);
|
||||
}
|
||||
|
||||
List list = new ArrayList();
|
||||
|
||||
private void assertInitialState() {
|
||||
int count = jdbcTemplate.queryForInt("select count(*) from T_FOOS");
|
||||
assertEquals(0, count);
|
||||
}
|
||||
|
||||
public void testSunnyDay() throws Exception {
|
||||
|
||||
assertInitialState();
|
||||
|
||||
container.setMessageListener(new SessionAwareMessageListener() {
|
||||
public void onMessage(Message message, Session session) throws JMSException {
|
||||
list.add(message.toString());
|
||||
jdbcTemplate.execute("INSERT into T_FOOS (id,name,foo_date) values (1,'bar',null)");
|
||||
}
|
||||
});
|
||||
|
||||
container.start();
|
||||
|
||||
// Need to sleep for at least a second here...
|
||||
Thread.sleep(1000L);
|
||||
|
||||
assertEquals(1, list.size());
|
||||
|
||||
String foo = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
assertEquals(null, foo);
|
||||
|
||||
int count = jdbcTemplate.queryForInt("select count(*) from T_FOOS");
|
||||
assertEquals(1, count);
|
||||
|
||||
}
|
||||
|
||||
public void testRollback() throws Exception {
|
||||
|
||||
assertInitialState();
|
||||
|
||||
container.setMessageListener(new SessionAwareMessageListener() {
|
||||
public void onMessage(Message message, Session session) throws JMSException {
|
||||
list.add(message.toString());
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
jdbcTemplate.execute("INSERT into T_FOOS (id,name,foo_date) values (1,'bar',null)");
|
||||
// This causes the DB to rollback but not the message
|
||||
throw new RuntimeException("Rollback!");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
container.start();
|
||||
|
||||
// Need to sleep for at least a second here...
|
||||
Thread.sleep(3000L);
|
||||
|
||||
// We rolled back so the message might come in many times...
|
||||
assertTrue(list.size() > 1);
|
||||
|
||||
int count = jdbcTemplate.queryForInt("select count(*) from T_FOOS");
|
||||
assertEquals(0, count);
|
||||
|
||||
String foo = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
assertEquals("foo", foo);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.jms;
|
||||
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Session;
|
||||
|
||||
import org.springframework.jms.connection.SessionProxy;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.jms.core.SessionCallback;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationAdapter;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
public class SynchronousTests extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
|
||||
private JmsTemplate jmsTemplate;
|
||||
|
||||
public void setJmsTemplate(JmsTemplate jmsTemplate) {
|
||||
this.jmsTemplate = jmsTemplate;
|
||||
}
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { ClassUtils.classPackageAsResourcePath(getClass()) + "/synch.xml" };
|
||||
}
|
||||
|
||||
protected void onSetUpBeforeTransaction() throws Exception {
|
||||
super.onSetUpBeforeTransaction();
|
||||
String foo = "";
|
||||
int count = 0;
|
||||
while (foo != null && count < 100) {
|
||||
foo = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
count++;
|
||||
}
|
||||
jdbcTemplate.execute("delete from T_FOOS");
|
||||
jmsTemplate.convertAndSend("queue", "foo");
|
||||
}
|
||||
|
||||
protected void onSetUpInTransaction() throws Exception {
|
||||
super.onSetUpInTransaction();
|
||||
}
|
||||
|
||||
private void assertInitialState() {
|
||||
int count = jdbcTemplate.queryForInt("select count(*) from T_FOOS");
|
||||
assertEquals(0, count);
|
||||
}
|
||||
|
||||
public void testCommit() throws Exception {
|
||||
|
||||
assertInitialState();
|
||||
String foo = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
assertEquals("foo", foo);
|
||||
jdbcTemplate.execute("INSERT into T_FOOS (id,name,foo_date) values (1,'bar',null)");
|
||||
|
||||
// force commit...
|
||||
setComplete();
|
||||
endTransaction();
|
||||
startNewTransaction();
|
||||
|
||||
// Database committed so this resord should be there...
|
||||
int count = jdbcTemplate.queryForInt("select count(*) from T_FOOS");
|
||||
assertEquals(1, count);
|
||||
|
||||
// ... the commit should also have cleared the queue, so this should now
|
||||
// be null
|
||||
foo = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
assertEquals(null, foo);
|
||||
|
||||
}
|
||||
|
||||
public void testFullRollback() throws Exception {
|
||||
|
||||
assertInitialState();
|
||||
String foo = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
assertEquals("foo", foo);
|
||||
jdbcTemplate.execute("INSERT into T_FOOS (id,name,foo_date) values (1,'bar',null)");
|
||||
|
||||
// force rollback...
|
||||
endTransaction();
|
||||
startNewTransaction();
|
||||
|
||||
// The database connection rolled back...
|
||||
int count = jdbcTemplate.queryForInt("select count(*) from T_FOOS");
|
||||
assertEquals(0, count);
|
||||
|
||||
// ... and so did the message session. The rollback should have restored
|
||||
// the queue, so this should now be non-null
|
||||
foo = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
assertEquals("foo", foo);
|
||||
|
||||
}
|
||||
|
||||
public void testPartialRollback() throws Exception {
|
||||
|
||||
assertInitialState();
|
||||
String foo = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
assertEquals("foo", foo);
|
||||
jdbcTemplate.execute("INSERT into T_FOOS (id,name,foo_date) values (1,'bar',null)");
|
||||
|
||||
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
|
||||
public void beforeCommit(boolean readOnly) {
|
||||
// Simulate a message system failure before the main transaction
|
||||
// commits...
|
||||
jmsTemplate.execute(new SessionCallback() {
|
||||
public Object doInJms(Session session) throws JMSException {
|
||||
try {
|
||||
assertTrue("Not a SessionProxy - wrong spring version?", session instanceof SessionProxy);
|
||||
((SessionProxy) session).getTargetSession().rollback();
|
||||
}
|
||||
catch (JMSException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (Exception e) {
|
||||
// swallow it
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// force commit...
|
||||
setComplete();
|
||||
endTransaction();
|
||||
startNewTransaction();
|
||||
|
||||
// The database portion committed...
|
||||
int count = jdbcTemplate.queryForInt("select count(*) from T_FOOS");
|
||||
assertEquals(1, count);
|
||||
|
||||
// ...but the JMS session rolled back, so the message is still there
|
||||
foo = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
assertEquals("foo", foo);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,161 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.jms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
||||
import org.springframework.transaction.support.TransactionCallback;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
public class TransactionPropagationTests extends AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] { ClassUtils.classPackageAsResourcePath(getClass()) + "/tx.xml" };
|
||||
}
|
||||
|
||||
private JmsTemplate jmsTemplate;
|
||||
|
||||
private PlatformTransactionManager transactionManager;
|
||||
|
||||
public void setTransactionManager(PlatformTransactionManager transactionManager) {
|
||||
this.transactionManager = transactionManager;
|
||||
}
|
||||
|
||||
public void setJmsTemplate(JmsTemplate jmsTemplate) {
|
||||
this.jmsTemplate = jmsTemplate;
|
||||
}
|
||||
|
||||
protected void onSetUp() throws Exception {
|
||||
super.onSetUp();
|
||||
String foo = "";
|
||||
int count = 0;
|
||||
while (foo != null && count < 100) {
|
||||
foo = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
count++;
|
||||
}
|
||||
jmsTemplate.convertAndSend("queue", "foo");
|
||||
jmsTemplate.convertAndSend("queue", "bar");
|
||||
jmsTemplate.convertAndSend("queue", "spam");
|
||||
}
|
||||
|
||||
List list = new ArrayList();
|
||||
|
||||
public void testRollbackOuterTransaction() throws Exception {
|
||||
|
||||
final DefaultTransactionDefinition transactionDefinition = new DefaultTransactionDefinition(
|
||||
TransactionDefinition.PROPAGATION_MANDATORY);
|
||||
|
||||
try {
|
||||
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
|
||||
new TransactionTemplate(transactionManager, transactionDefinition)
|
||||
.execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
String msg = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
list.add(msg);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
new TransactionTemplate(transactionManager, transactionDefinition)
|
||||
.execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
String msg = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
list.add(msg);
|
||||
throw new RuntimeException("Rollback!");
|
||||
}
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
fail("Expected RuntimeException");
|
||||
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
// Expected
|
||||
assertEquals("Rollback!", e.getMessage());
|
||||
}
|
||||
|
||||
List msgs = getMessages();
|
||||
System.err.println(list);
|
||||
System.err.println(msgs);
|
||||
|
||||
// 2 received
|
||||
assertEquals(2, list.size());
|
||||
// but both rolled back...
|
||||
assertEquals(3, msgs.size());
|
||||
}
|
||||
|
||||
public void testRollbackSingleTransaction() throws Exception {
|
||||
|
||||
try {
|
||||
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
|
||||
String msg = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
list.add(msg);
|
||||
msg = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
list.add(msg);
|
||||
throw new RuntimeException("Rollback!");
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
fail("Expected RuntimeException");
|
||||
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
// Expected
|
||||
assertEquals("Rollback!", e.getMessage());
|
||||
}
|
||||
|
||||
List msgs = getMessages();
|
||||
System.err.println(list);
|
||||
System.err.println(msgs);
|
||||
|
||||
// 2 received
|
||||
assertEquals(2, list.size());
|
||||
// but both rolled back...
|
||||
assertEquals(3, msgs.size());
|
||||
}
|
||||
|
||||
private List getMessages() {
|
||||
String next = "";
|
||||
List msgs = new ArrayList();
|
||||
while (next != null) {
|
||||
next = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
if (next != null)
|
||||
msgs.add(next);
|
||||
}
|
||||
return msgs;
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
|
||||
|
||||
<import resource="classpath:/data-source.xml"/>
|
||||
|
||||
<!-- Transaction manager for a datasource -->
|
||||
<bean id="transactionManager"
|
||||
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
<!-- Transaction manager for jms -->
|
||||
<bean id="jmsTransactionManager" autowire-candidate="false"
|
||||
class="org.springframework.jms.connection.JmsTransactionManager">
|
||||
<property name="connectionFactory" ref="connectionFactory"/>
|
||||
</bean>
|
||||
|
||||
<bean id="jmsTemplate"
|
||||
class="org.springframework.jms.core.JmsTemplate">
|
||||
<property name="connectionFactory" ref="connectionFactory" />
|
||||
<property name="receiveTimeout" value="100" />
|
||||
<!-- This is important... -->
|
||||
<property name="sessionTransacted" value="true" />
|
||||
</bean>
|
||||
|
||||
<bean id="jdbcTemplate"
|
||||
class="org.springframework.jdbc.core.JdbcTemplate">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
<!-- The TransactionAwareConnectionFactoryProxy actually doesn't add any value here
|
||||
because the same behaviour is built into the DefaultMessageListenerContainer -->
|
||||
<!-- bean id="connectionFactory"
|
||||
class="org.apache.activemq.ActiveMQConnectionFactory">
|
||||
<property name="brokerURL">
|
||||
<value>vm://localhost</value>
|
||||
</property>
|
||||
</bean-->
|
||||
|
||||
<bean id="connectionFactory"
|
||||
class="org.springframework.jms.connection.TransactionAwareConnectionFactoryProxy">
|
||||
<property name="targetConnectionFactory">
|
||||
<bean class="org.apache.activemq.ActiveMQConnectionFactory" depends-on="brokerService">
|
||||
<property name="brokerURL">
|
||||
<value>vm://localhost</value>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="synchedLocalTransactionAllowed" value="true" />
|
||||
</bean>
|
||||
|
||||
<bean id="container"
|
||||
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
|
||||
<property name="autoStartup" value="false" />
|
||||
<property name="transactionManager" ref="jmsTransactionManager" />
|
||||
<property name="connectionFactory" ref="connectionFactory" />
|
||||
<property name="destinationName" value="queue" />
|
||||
<!-- This is important... it forces the container to acknowledge message receipt,
|
||||
and avoid duplicate messages in the sunny day case -->
|
||||
<property name="sessionTransacted" value="true" />
|
||||
<property name="messageListener">
|
||||
<bean
|
||||
class="org.springframework.jms.listener.adapter.MessageListenerAdapter" />
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -1,46 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
|
||||
|
||||
<import resource="classpath:/data-source.xml"/>
|
||||
|
||||
<!-- Transaction manager for a datasource -->
|
||||
<bean id="transactionManager"
|
||||
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="jmsTemplate"
|
||||
class="org.springframework.jms.core.JmsTemplate">
|
||||
<property name="connectionFactory" ref="connectionFactory" />
|
||||
<property name="receiveTimeout" value="100" />
|
||||
<!-- This is important... -->
|
||||
<property name="sessionTransacted" value="true" />
|
||||
</bean>
|
||||
|
||||
<!-- bean id="connectionFactory"
|
||||
class="org.apache.activemq.ActiveMQConnectionFactory">
|
||||
<property name="brokerURL">
|
||||
<value>vm://localhost</value>
|
||||
</property>
|
||||
</bean-->
|
||||
|
||||
<bean id="connectionFactory"
|
||||
class="org.springframework.jms.connection.TransactionAwareConnectionFactoryProxy">
|
||||
<property name="targetConnectionFactory">
|
||||
<bean class="org.apache.activemq.ActiveMQConnectionFactory" depends-on="brokerService">
|
||||
<property name="brokerURL">
|
||||
<value>vm://localhost</value>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="synchedLocalTransactionAllowed" value="true" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -1,44 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
|
||||
|
||||
<!-- Transaction manager for jms -->
|
||||
<bean id="transactionManager"
|
||||
class="org.springframework.jms.connection.JmsTransactionManager">
|
||||
<property name="connectionFactory" ref="connectionFactory"/>
|
||||
</bean>
|
||||
|
||||
<bean id="jmsTemplate"
|
||||
class="org.springframework.jms.core.JmsTemplate">
|
||||
<property name="connectionFactory" ref="connectionFactory" />
|
||||
<property name="receiveTimeout" value="100" />
|
||||
<!-- This is important... -->
|
||||
<property name="sessionTransacted" value="true" />
|
||||
</bean>
|
||||
|
||||
<bean id="connectionFactory"
|
||||
class="org.apache.activemq.ActiveMQConnectionFactory">
|
||||
<property name="brokerURL">
|
||||
<value>vm://localhost</value>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!--bean id="connectionFactory"
|
||||
class="org.springframework.jms.connection.TransactionAwareConnectionFactoryProxy">
|
||||
<property name="targetConnectionFactory">
|
||||
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
|
||||
<property name="brokerURL">
|
||||
<value>vm://localhost</value>
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
<property name="synchedLocalTransactionAllowed" value="true" />
|
||||
</bean-->
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user