» Publishers, Monetize your RSS feeds with FeedShow: More infos (Show/Hide Ads)
Spring Portlet MVCThe Spring Portlet MVC framework provides a complete MVC layer for the JSR-168 Portlet API in the same way that Spring Web MVC does for the Servlet API. Wherever possible the APIs and capabilities are the same between the two frameworks. However, unlike most other portlet MVC frameworks, the unique workflow of the JSR-168 API is completely preserved, including the separation of the ActionRequest and the RenderRequest. DownloadsSpring Portlet MVC has been part of the core Spring Framework Using Spring 2.0, the spring-portlet.jar file from the dist/extmodules directory needs to be included in your webapp libraries along with either dist/spring.jar or a number of libraries from dist/modules. Using Spring 2.5, the modules have been reorganized and the library has been renamed spring-webmvc-portlet.jar and also requires spring-webmvc.jar. DocumentationThe framework is fully documented as part of the Spring Framework Reference Manual There are training slides available from the Spring Portlet MVC Seminar SamplesThere is a small sample webapp for use with the current framework. It demonstrates a lot of the uniqueness of the Spring Portlet MVC framework and provides a good template for starting a new Spring Portlet project. The sample source code is available for download here There is also now a small sample application included with the Spring Framework distribution itself. See the samples/petportal directory in the distribution for more information. QuestionsIf you have questions about using Spring Portlet MVC, please post them in the Spring Framework Support Forums There is also a Frequently Asked Questions area available here for Spring Portlet MVC – please review it before posting your questions. Bugs & EnhancementsPlease enter any bugs or enhancement requests into the Spring JIRA Issue Tracker FeedbackPlease send any other feedback on Spring Portlet MVC or on this site directly to me: jlewis -|AT|- unicon -|DOT|- net Thanks for trying out the Spring Portlet MVC Framework! |
Recent NewsSince I just answered this questions in the forums, I thought I would post the same information here. I expect that there will be JSR 286 support in Spring Portlet MVC as part of Spring 3.0. As for a likely release date, you'll have to bug Juergen for that. We had been hoping to do the development and testing using the Pluto 2.0 portlet container, since that is slated to be the reference implementation for the spec. However,... I can't believe it's been well over a year since I updated this page. While there has been a lot of great work going on in the background using and evolving Spring Portlet MVC, there hasn't been much to post here for a while – I guess that speaks to how stable the framework has become. Thanks to everyone for all their great questions in the forums – I am tremendously pleased at how widely adopted this framework has become in the niche community of Java Portlet developers.... The first complete draft of the chapter for Spring Framework Reference Manual is now available. It will be included with the RC1 release. Please send any feedback you have about the draft so we can continue to improve it before the final release of Spring 2.0. |
Changes between revision 59 and revision 60:
FTP adapters
The FTP adapters have been evicted from the main Spring Integration project before the 1.0.0.RELEASE. The main reasoning behind this was to avoid having to support something that we were not too sure we got right. In retrospect this has been a good decision, it has allowed some changes that would not have been possible had we committed to backwards compatibility.
Since spring of 2009 the FTP adapters have been stable and are in use in production in several projects.
Overview
The FTP adapters are for you if you need to read files from a remote FTP directory, or write files to a similar drop box. They're aimed to cover all the simple ftp scenarios and be extensible for more complex cases. For inbound ftp use cases there is the the FtpFileSource. For outbound scenarios the FtpSendingMessageConsumer.
Inbound: FtpFileSource
The FtpFileSource is composed of an FtpInboundSynchronizer and a FileReadingMessageSource. The latter is documented in Spring Integration itself. The FtpInboundSynchronizer will pull files from the remote ftp directory and write them to the local directory (renaming them once the transfer is complete). The FtpInboundSynchronizer needs an FTPClientPool to do it's job.
So first configure the FtpFileSource:
<integration:inbound-channel-adapter channel="file-channel" ref="ftpFileSource" /> <beans:bean id="ftpFileSource" class="org.springframework.integration.ftp.FtpFileSource"> <beans:property name="clientPool" ref="ftpClientPool" /> <beans:property name="localWorkingDirectory" value="file:${java.io.tmpdir}/FtpConfigIntegrationTests" /> <beans:property name="taskScheduler" ref="taskScheduler" /> <beans:property name="trigger"> <beans:bean class="org.springframework.integration.scheduling.IntervalTrigger"> <beans:constructor-arg value="1500" /> </beans:bean> </beans:property> </beans:bean>
The trigger property is optional, by default an interval of 10 seconds is used.
Next we set up the FTPClientPool:
<bean id="ftpClientPool" class="org.springframework.integration.ftp.QueuedFTPClientPool"> <constructor-arg> <bean class="org.springframework.integration.ftp.DefaultFTPClientFactory"> <property name="host" value="${ftp.host}"/> <property name="username" value="${ftp.username}"/> <property name="password" value="${ftp.password}"/> <property name="port" value="${ftp.port}"/> <property name="remoteWorkingDirectory" value="${ftp.remotedir}"/> </bean> </constructor-arg> </bean>
The client factory can be customized in the pool, but for more exotic ftp setups you can also extend or replace the QueuedFTPClientPool.
Outbound: FtpSendingMessageConsumer
For outbound scenarios you need to setup an FtpSendingMessageConsumer as an endpoint. The pooling is identical to the inbound setup.
<integration:outbound-channel-adapter ref="consumer" channel="file-channel" /> <beans:bean id="consumer" class="org.springframework.integration.ftp.FtpSendingMessageConsumer"> <beans:property name="ftpClientPool" ref="outboundPool" /> </beans:bean>
Changes between revision 4 and revision 5:
Extensions for Spring Integration
Introduction
The number of protocols in active use is astonishing. However, integrating an adapter for one of these protocols with Spring Integration using the appropriate library is usually quite trivial. For example a twitter adapter using Twitter4J shouldn't take more that 10 lines of code. For that reason SESIA will never be a large project. It will also be under constant flux.
Once a code base is mature enough to be considered a candidate for addition to the Spring Integration project, it can first be ironed out and exposed through SESIA for early adopters. Adapters that are not interesting for the majority of SI users, but are interesting for many SI users can be kept in SESIA to keep the main project light. If you choose to use SESIA adapters, you will either pick a build number use that jar trusting the developer hasn't gone off track, or you will take the code from the repository and add it to your own code base. Typically you'll have a handful of classes to copy, so it might be easy to maintain them yourself. All Spring Extensions are made available under the Apache license, so you're free to do pretty much everything you'll ever need to to the code.
I'll include all adapters here.
FTP adapters
The FTP adapters have been evicted from the main Spring Integration project before the 1.0.0.RELEASE. The main reasoning behind this was to avoid having to support something that we were not too sure we got right. In retrospect this has been a good decision, it has allowed some changes that would not have been possible had we committed to backwards compatibility.
Since spring of 2009 the FTP adapters have been stable and are in use in production in several projects.
Overview
The FTP adapters are for you if you need to read files from a remote FTP directory, or write files to a similar drop box. They're aimed to cover all the simple ftp scenarios and be extensible for more complex cases. For inbound ftp use cases there is the the FtpFileSource. For outbound scenarios the FtpSendingMessageConsumer.
Inbound: FtpFileSource
The FtpFileSource is composed of an FtpInboundSynchronizer and a FileReadingMessageSource. The latter is documented in Spring Integration itself. The FtpInboundSynchronizer will pull files from the remote ftp directory and write them to the local directory (renaming them once the transfer is complete). The FtpInboundSynchronizer needs an FTPClientPool to do it's job.
So first configure the FtpFileSource:
<integration:inbound-channel-adapter channel="file-channel" ref="ftpFileSource" /> <beans:bean id="ftpFileSource" class="org.springframework.integration.ftp.FtpFileSource"> <beans:property name="clientPool" ref="ftpClientPool" /> <beans:property name="localWorkingDirectory" value="file:${java.io.tmpdir}/FtpConfigIntegrationTests" /> <beans:property name="taskScheduler" ref="taskScheduler" /> <beans:property name="trigger"> <beans:bean class="org.springframework.integration.scheduling.IntervalTrigger"> <beans:constructor-arg value="1500" /> </beans:bean> </beans:property> </beans:bean>
The trigger property is optional, by default an interval of 10 seconds is used.
Next we set up the FTPClientPool:
<beans:bean id="ftpClientPool" class="org.springframework.integration.ftp.QueuedFTPClientPool"> <beans:constructor-arg> <beans:bean class="org.springframework.integration.ftp.DefaultFTPClientFactory"/> </beans:constructor-arg> </beans:bean>
The client factory can be customized in the pool, but for more exotic ftp setups you can also extend or replace the QueuedFTPClientPool.
Outbound: FtpSendingMessageConsumer
For outbound scenarios you need to setup an FtpSendingMessageConsumer as an endpoint. The pooling is identical to the inbound setup.
<integration:outbound-channel-adapter ref="consumer" channel="file-channel" /> <beans:bean id="consumer" class="org.springframework.integration.ftp.FtpSendingMessageConsumer"> <beans:property name="ftpClientPool" ref="outboundPool" /> </beans:bean>
That's all folks
If something is missing you're very welcome to contribute. If you want to submit your own adapter project:
- sign over your soul

- create an issue

- attach your patch, zipped project
The more you help me, the more likely it is that your code will be included in the build![]()
h1 Spring Integration
The Spring Integration project
Somewhat confusingly there is a project called Spring Integration
, if you're looking for ways to integrate a third party product with Spring, look at the bottom section. The Spring Integration project aims at providing a framework for implementing Enterprise Integration Patterns as described by Gregor Hohpe and Bobby Woolf. The project contains a handful of adapters for the most common integration need. However, there are an extreme amount of integration protocols thinkable.
To avoid the core framework growing into an unwieldy blob the committers have chosen to put less mainstream adapters into a Spring Extensions project code named SESIA. The documentation for SESIA is maintained on this wiki.
Integrate with Spring
This section contains code snippets, hints and tips for integrating Spring with 3rd party products that are not explicitly covered as part of the core framework. For components that are included are part of the Spring distribution check out the reference manual for information on how they work with Spring.
3rd Party Product List
Articles
.diffadded{background: #ddffdd;padding:1px 1px 1px 4px;border-left: 4px solid darkgreen;} .diffdeleted{color:#999;background: #ffdddd;padding: 1px 1px 1px 4px;border-left: 4px solid darkred;} .diffnochange{padding:1px 1px 1px 4px;border-left: 4px solid #d3d3d3;} .differror{background:brown;} .diff{font-family:lucida console, courier new, fixed-width;font-size: 12px;line-height: 14px;} .diffaddedchars{background-color:#99ff99;font-weight:bolder;} .diffremovedchars{background-color:#ff9999;text-decoration: line-through;font-weight:bolder;} .diffnav{display:none;}Changes between revision 5 and revision 6:
<a href="http://woxiva.com">hovipi</a> | [url=http://nizene.com]virica[/url] | [link=http://kuroxu.com]tyxuza[/link] | http://cazezu.com
| hosaxu | [http://kezize.com zineku]
Space Index
|
|||||||||||||||||||||||||||||||
0-9 |
Amodified version of the Petclinic sample is here showing a DWR front end. The Clinic object is exported and made available to the local JavaScript functions from the index.html page. It's not complete, only some of the functionality is implemented, but it should give you eneough of a head ...
|
||||||||||||||||||||||||||||||
B |
Cmacro solution to single checkboxes. The default macros files that come with spring for Freemarker http://www.freemarker.org and Velocity http://jakarta.apache.org/velocity/ are very good at providing a base infrastructure for creating web documents. However they are a base and adding further macros ...
|
||||||||||||||||||||||||||||||
D |
E |
||||||||||||||||||||||||||||||
FIntro FOP http://xml.apache.org/fop/index.html is an XSLT driven print formatter capable of rendering to different output types such as PDF or SVG. It's pretty simple to extend the Spring view classes to implement a FOP view and so enable dynamic ...
you've ever tried to put multiple forms on the same web page and bind to their form bean (command) properties, then hook various controllers to them you will have rapidly run into a variety of issues. most especially if you are dealing with controllers (such as the SimpleFormController ...
|
G |
||||||||||||||||||||||||||||||
HCookbook is a collection of short Spring examples. Some highlight how to get started with standard Spring technologies, some show how to use Spring with other technologies where no standard integration code is included in the Spring codebase. Feel free to add ...
|
I |
||||||||||||||||||||||||||||||
Jauthor of this page is actually JorisPZ from Spring Forums original thread here http://forum.springframework.org/viewtopic.php?p=30741#30741 This cookbook describes how to setup global transactions using Spring's JtaTransactionManager, JOTM, a RDBMS and the ActiveMQ JMS provider ...
following is what I pieced together from certain sources of how Jencks could be configured for JTA using the OracleXA driver to connect to Oracle.
|
K |
||||||||||||||||||||||||||||||
L |
M |
||||||||||||||||||||||||||||||
N |
O |
||||||||||||||||||||||||||||||
P |
Q |
||||||||||||||||||||||||||||||
R |
Sanyone developing web services with Axis, it can be tricky to get a large number of different web services to share a common application context or make use of the web application context if Axis is bundled inside of a WAR in servlet form. Often, developers ...
|
||||||||||||||||||||||||||||||
T |
Ustandard way to resolve views in a Spring web application is to turn each view resolution request into the name of a web page. But sometimes we don't necessarily want to do this. This example explores a situation I encountered where I wanted to use ...
|
||||||||||||||||||||||||||||||
V |
W |
||||||||||||||||||||||||||||||
XEffectively, a custom View implementation that uses XMLC could look as follows without any XMLCspecific base class shipped in Spring: public abstract class MyXmlcView extends AbstractView { protected void renderMergedOutputModel( Map model, HttpServletRequest request, HttpServletResponse ...
|
Y |
||||||||||||||||||||||||||||||
Z |
!@#$ |
||||||||||||||||||||||||||||||
Thanks for the great article.
It is working excellently when I have just one command class (You call it form bean) which has some boolean property.
But I'm facing the issue when I have command class with list of objects when each of them has some boolean property.
For instance, I'm trying something similar to:
<#list command.getSegmentations() as segmentation>
<tr>
<td><@external.formCheckbox "segmentation.selected", ""/></td>
</#list>
But the problem is while binding to "segmentation".
Will be very grateful for any suggestions.
Best,
Taras
A macro solution to single checkboxes.
The default macros files that come with spring for Freemarker
and Velocity
are very good at providing a base infrastructure for creating web documents. However they are a base and adding further macros is often required to create anythingmore than a basic web site. One aspect of this is that the formCheckboxes macro is designed to work with a collection of values in order to create multiple checkboxes. This can be useful but many people want to create just one checkbox and map it directly to a boolean property of the command class. In addition there can be problems if you try and map to a boolean property and want that property to be one by default.
There has been much discussion in the forums about dealing with checkboxes and most specifically handling them considering that the default browser behaviour is to not return any request parameter for a checkbox unless it is ticked (true). The default formCheckbox macro does not appear to handle this either.
Note: I find this notion of refering to the bean backing the form as a Command to be a bit missleading. I prefer to call it a Form Bean (ala struts). To me this is much closer to it's function and easer to understand.
This cook book page attempts to provide information and code on doing the following:
- Provide a macro for dealing with a single checkbox and matching boolean value.
- Handle both default values (true and false) for a checkbox.
Lets start by looking at my custom macro which I have coded in a file called macros.ftl:
[ftl] <#-- * formCheckbox * * Show a single checkbox and also include a hidden marker field so that an un-checked * checkbox still presents a false value back to the form. * * For details on the _Hidden field usange. Refer to * http://www.springframework.org/docs/api/org/springframework/web/bind/WebDataBinder.html#setFieldMarkerPrefix(java.lang.String) * * @param path the name of the field to bind to * @param attributes any additional attributes for the element (such as class or CSS styles or size --> [#macro formCheckbox path attributes=""] [@spring.bind path /] <input type="hidden" name="_${spring.status.expression}" value="false" /> <input type="checkbox" id="${spring.status.expression}" name="${spring.status.expression}" [#if spring.status.value]checked="checked"[/#if] ${attributes} [@spring.closeTag/] [/#macro]
I'll work through it's design in order of appearance:
- [ftl] - I use Freemarker
templates and this tag indicates to freemarker that I am using square brackets [] around freemarker tags. I prefer this method because it helps me to clearly see freemarker markup in the templates and doesn't confuse editors. If you are using the default brackets <> or Velocity
then you won't need this tag. - [#macro formCheckbox path attributes=""] - Because we are only dealing with a single checkbox we don't need to be passed a collection or delimiter HTML. So the only parameters we need are the path the bind to to get the data and and extra formatting tags.
- [@spring.bind path /] - Slightly different. Freemarker ensures that each macro file has it's own namespace in the model. So in order to access anything contained in the spring.ftl file of default macros, I have to prefix it with spring. Note that the path will be bound inside the spring namespace, even though we are calling from a different namespace.
- <input type="hidden" name="*_$Unknown macro: {spring.status.expression}" value="false" />_* _- This is a new addition over the default macro. According to the documentation for the____[WebDataBinder|http}
package myapp.spring.formbeans;
public class MyFormBean {
private boolean checkboxValue = true;
public boolean isCheckboxValue() {
return this.checkboxValue;
}
public void setCheckboxValue(boolean checkboxValue)
You can see how simple this now is. Nothing else is required. I.e. no extra data bindings or property editors.
How does this work ?
Basically on submission of the form, spring creates a new instance of your form bean and populates it with values from the form. If the checkbox has been ticked then the bean is populated with true. If the checkbox has not been ticked therefore not sending a parameter back in the request, then spring automatically looks at the '_' prefixed hidden field and grabs the value from that. Because we have hard coded this in the macro to be false, the form bean gets set to false, thus being correct.
I have deliberately coded the above form bean with a default of true for the property because in this example I wanted the check box to initially be on. When looking at this problem, I initially did this without the hidden form field providing a default. When the form was submitted, spring created a new form bean (default true) and then did nothing because there was no matching parameter in the request. The visible effect of not having the hidden field is that when you submit, spring executes the code with a true value and when you come back to your form, the check box is turned on again.
Show me the template !
[#ftl] [#import "spring.ftl" as spring /] [#import "macros.ftl" as lp /] <html> <head> </head> <body> <h2>[@spring.message "mypage.title"/]</h2> <form action="${webroot}/accounts/dosomething.form" method="POST"> <table> <tr> <td></td> <td>[@lp.formCheckbox "formBeanName.checkboxValue", "" /] [@spring.message "myapp.checkbox.fieldname"/]</td> </tr> </table> <input type="submit" value="[@spring.message "myapp.submit.buttontext"/]" /> </form></body></html>
There's not much to it because our macro is doing the hard work. Remember I am using square brackets around my freemarker directives. Anything else in ${} is a reference to a data item sitting in the freemarker model. Note the two import statements at the top. These import the two macros files we need. Firstly the spring.ftl which defines the bind macro and secondly our macros.ftl. Remember freemarker ensures that each macros library lives in it's own namespace in the freemarker model, so in this case our custom check box macro is in the lp name space.
This cook book could be a great source of ideas and inspiration, but all this spam is a pain.
It looks unprofessional and doesn't fit in with the image I and most people I know have of SpringSource. Clean this mess up by forcing people to register.
Cookbook is a collection of short Spring examples. Some highlight how to get started with standard Spring technologies, some show how to use Spring with other technologies where no standard integration code is included in the Spring codebase.
Feel free to add new pages to this space. The list below will automatically update to keep a current index of available recipes.
Space Index
|
|||||||||||||||||||||||||||||||
0-9 |
Amodified version of the Petclinic sample is here showing a DWR front end. The Clinic object is exported and made available to the local JavaScript functions from the index.html page. It's not complete, only some of the functionality is implemented, but it should give you eneough of a head ...
|
||||||||||||||||||||||||||||||
B |
Cmacro solution to single checkboxes. The default macros files that come with spring for Freemarker http://www.freemarker.org and Velocity http://jakarta.apache.org/velocity/ are very good at providing a base infrastructure for creating web documents. However they are a base and adding further macros ...
|
||||||||||||||||||||||||||||||
D |
E |
||||||||||||||||||||||||||||||
FIntro FOP http://xml.apache.org/fop/index.html is an XSLT driven print formatter capable of rendering to different output types such as PDF or SVG. It's pretty simple to extend the Spring view classes to implement a FOP view and so enable dynamic ...
you've ever tried to put multiple forms on the same web page and bind to their form bean (command) properties, then hook various controllers to them you will have rapidly run into a variety of issues. most especially if you are dealing with controllers (such as the SimpleFormController ...
|
G |
||||||||||||||||||||||||||||||
HCookbook is a collection of short Spring examples. Some highlight how to get started with standard Spring technologies, some show how to use Spring with other technologies where no standard integration code is included in the Spring codebase. Feel free to add ...
|
I |
||||||||||||||||||||||||||||||
Jauthor of this page is actually JorisPZ from Spring Forums original thread here http://forum.springframework.org/viewtopic.php?p=30741#30741 This cookbook describes how to setup global transactions using Spring's JtaTransactionManager, JOTM, a RDBMS and the ActiveMQ JMS provider ...
following is what I pieced together from certain sources of how Jencks could be configured for JTA using the OracleXA driver to connect to Oracle.
|
K |
||||||||||||||||||||||||||||||
L |
M |
||||||||||||||||||||||||||||||
N |
O |
||||||||||||||||||||||||||||||
P |
Q |
||||||||||||||||||||||||||||||
R |
Sanyone developing web services with Axis, it can be tricky to get a large number of different web services to share a common application context or make use of the web application context if Axis is bundled inside of a WAR in servlet form. Often, developers ...
|
||||||||||||||||||||||||||||||
T |
Ustandard way to resolve views in a Spring web application is to turn each view resolution request into the name of a web page. But sometimes we don't necessarily want to do this. This example explores a situation I encountered where I wanted to use ...
|
||||||||||||||||||||||||||||||
V |
W |
||||||||||||||||||||||||||||||
XEffectively, a custom View implementation that uses XMLC could look as follows without any XMLCspecific base class shipped in Spring: public abstract class MyXmlcView extends AbstractView { protected void renderMergedOutputModel( Map model, HttpServletRequest request, HttpServletResponse ...
|
Y |
||||||||||||||||||||||||||||||
Z |
!@#$ |
||||||||||||||||||||||||||||||
Below is my configuration using ibm mq that is throwing the exception as given after the config....ppl plz throw some light... i m doing this to test whether i can put a commit count in place when using a platform transaction manager that is used when placing a transaction manager within the dmlc container as given below...com.MessageListener is nothing but DMLC with the abstractpollingcontainer receiveAndExecute method overriden where i place the condition to do commit....
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:txn.properties" />
</bean>
<!- For JMS based listener ->
<bean id="msgListener" class="com.MyMessageListener"></bean>
<!- JMS Container listening on source queue org.springframework.jms.listener.DefaultMessageListenerContainer->
<bean id="jmsContainer" class="com.MyContainer" lazy-init="false">
<property name="connectionFactory" ref="sourceQCFCredential" />
<property name="destination" ref="sourceQueue" />
<property name="messageListener" ref="msgListener" />
<property name="concurrentConsumers" value="1" />
<property name="sessionAcknowledgeModeName"
value="CLIENT_ACKNOWLEDGE" />
<!- <property name="sessionTransacted" value="true"/> ->
<property name="transactionManager" ref="transactionManager" />
</bean>
<!- MQ Connection factory setup ->
<bean id="sourceQCF"
class="com.ibm.mq.jms.MQXAQueueConnectionFactory">
<property name="transportType" value="1" />
<property name="queueManager" value="$
" />
<property name="hostName" value="$
<property name="port" value="$
<property name="channel" value="$
</bean>
<!- MQ queue setup ->
<bean id="sourceQueue" class="com.ibm.mq.jms.MQQueue">
<property name="baseQueueManagerName"
value="$
<property name="baseQueueName" value="$
</bean>
<!- User credential for source queue connection ->
<bean id="sourceQCFCredential"
class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
<property name="targetConnectionFactory" ref="connectionFactory" />
<property name="username" value="$
<property name="password" value="$
</bean>
<!
<bean id="qjmsTemplate"
class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="sourceQCFCredential" />
<property name="sessionAcknowledgeModeName"
value="CLIENT_ACKNOWLEDGE" />
<property name="sessionTransacted" value="true" />
<property name="defaultDestination" ref="sourceQueue" />
</bean>
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="userTransaction">
<ref local="jotm" />
</property>
</bean>
<bean id="connectionFactory"
class="org.jencks.pool.PooledSpringXAConnectionFactory">
<property name="connectionFactory" ref="sourceQCF"/>
<property name="transactionManager" ref="jotm" />
</bean>
<bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean" />
Exception in thread "main" org.springframework.jms.UncategorizedJmsException: Uncategorized exception occured during JMS processing; nested exception is javax.jms.JMSException: MQJMS1068: failed to obtain XAResource; nested exception is javax.transaction.xa.XAException: client connection not XA enabled
at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:292)
at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:168)
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:474)
at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:539)
at org.springframework.jms.core.JmsTemplate.convertAndSend(JmsTemplate.java:646)
at org.springframework.jms.core.JmsTemplate.convertAndSend(JmsTemplate.java:635)
at com.TransactionDriver.main(TransactionDriver.java:17)
Caused by: javax.jms.JMSException: MQJMS1068: failed to obtain XAResource
at com.ibm.mq.jms.services.ConfigEnvironment.newException(ConfigEnvironment.java:567)
at com.ibm.mq.jms.MQXAQueueConnection.createXAQueueSession(MQXAQueueConnection.java:108)
at com.ibm.mq.jms.MQXAQueueConnection.createXASession(MQXAQueueConnection.java:143)
at org.jencks.pool.XASessionPool.createSession(XASessionPool.java:108)
at org.jencks.pool.XASessionPool.makeObject(XASessionPool.java:72)
at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:974)
at org.jencks.pool.XASessionPool.borrowSession(XASessionPool.java:51)
at org.jencks.pool.PooledSpringXAConnection.createXASession(PooledSpringXAConnection.java:248)
at org.jencks.pool.PooledSpringXAConnection.createSession(PooledSpringXAConnection.java:277)
at org.springframework.jms.support.JmsAccessor.createSession(JmsAccessor.java:196)
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:462)
... 4 more
the author of this page is actually JorisPZ from Spring Forums - original thread here
This cookbook describes how to setup global transactions using Spring's JtaTransactionManager, JOTM, a RDBMS and the ActiveMQ JMS provider. Since all configuration takes place in Spring context files (so no need for JNDI), and JOTM is a standalone global transaction manager, this setup does not require a full blown J2EE container. The setup described below has been tested using Tomcat and MySQL.
The solution described below is a result of a few hours of trial-and-error, so better solutions might very well exist. If so, please update this page!
First, set up a JOTM instance, which is easily achieved using the Spring JotmFactoryBean:
<bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean"/>
The resulting bean should then be injected into the UserTransaction property of a JtaTransactionManager:
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="userTransaction"><ref local="jotm"/></property> </bean>
Now, we will set up two transactional resources, a RDBMS and a JMS provider. For this example we will use ActiveMQ.
We will use Enhydra's XAPool for providing XA connection pooling:
<bean id="dataSource" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown"> <property name="dataSource"> <bean class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown"> <property name="transactionManager" ref="jotm" /> <property name="driverName" value="$\{jdbc.driverClassName}" /> <property name="url" value="$\{jdbc.url}" /> </bean> </property> <property name="user" value="$\{jdbc.username}"/> <property name="password" value="$\{jdbc.password}"/> </bean>
Note that a reference to the JOTM bean is injected into the transactionManager property of the StandardXADataSource.
Next, we will setup a JMS connection factory. ActiveMQ comes with a connection factory (org.activemq.ActiveMQXAConnectionFactory) which provides XA capabale JMS connections. However, these connections do not automatically take part in Spring managed JTA transactions.
The solution to this problem is to wrap the ActiveMQXAConnectionFactory with a PooledSpringXAConnectionFactory. The code for the latter was kindly provided by Andy DePue, and can be downloaded here
.
<bean id="connectionFactory" class="com.marathon.jms.PooledSpringXAConnectionFactory"> <property name="connectionFactory"> <bean class="org.activemq.ActiveMQXAConnectionFactory"> <property name="brokerURL" value="$\{brokerURL}" /> </bean> </property> <property name="transactionManager" ref="jotm"/> </bean>
Note that again, a reference to the JOTM bean is injected into the transactionManager property of the PooledSpringXAConnectionFactory. (BTW, if you need to set a Client ID on the JMS connections, you should do this through the clientID property of the ActiveMQXAConnectionFactory.)
As an example of defining a JMS destination purely in Spring, the following fragment sets up an ActiveMQTopic:
<bean id="destination" class="org.activemq.message.ActiveMQTopic" autowire="constructor"> <constructor-arg> <value>myTopicName</value> </constructor-arg> </bean>
Finally, to use the convenient Spring JmsTemplate class, we set it up as follows:
<bean id="myJmsTemplate" class=" org.springframework.jms.core.JmsTemplate"> <property name="connectionFactory" ref="connectionFactory" /> </bean>
And that's it! Messages send or received through the JmsTemplate will now automatically take part in Spring managed JTA transactions.







