AspectJ support
From Spring 2.5 onwards, Spring’s AspectJ support can be utilised. In this example we first define a <tx:advice> that indicates that all methods starting with "get" are PROPAGATION_REQUIRED and all methods starting with "set" are PROPAGATION_REQUIRES_NEW. All other methods use the default transaction settings.
|
|
Another alternative mechanism for declaring transaction settings is to use the Spring annotation-based transaction support. This requires the use of Java 5+, and therefore cannot be used with WebSphere Application Server V6.0.2.x.
First add the following to the spring.xml configuration:
<tx:annotation-driven/>
|
The EJB 3.0 specification defines the Java Persistence API (JPA) as the means for providing portable persistent Java entities. WebSphere Application Server V7 and the WebSphere Application Server V6.1 EJB 3 feature pack both provide implementations of EJB 3 and JPA; it is also possible to use the Apache OpenJPA implementation of JPA with WebSphere Application Server V6.1
Using an Annotation style injection of a JPA EntityManager is possible:
@PersistenceContext |
<!-- bean post-processor for JPA annotations --> |
For JMS message sending or synchronous JMS message receipt, JMSTemplates can be used. This includes the use of Spring’s dynamic destination resolution functionality both via JNDI and true dynamic resolution.
The following example shows the configuration of a resource reference for a ConnectionFactory. This reference is mapped during application deployment to point to a configured, managed ConnectionFactory stored in the application server’s JNDI namespace. The ConnectionFactory is required to perform messaging and should be injected into the Spring JMSTemplate.
<resource-ref> |
<jee:jndi-lookup id="jmsConnectionFactory" jndi-name=" jms/myCF "/> |
JNDI resolution:
jmsTemplate.send("java:comp/env/jms/myQueue", messageCreator);
Dynamic resolution:
jmsTemplate.send("myQueue", messageCreator);
If you have been using the Spring Framework with WebSphere Application Server already, you may have come across this developerWorks article http://www.ibm.com/developerworks/websphere/techjournal/0609_alcott/0609_alcott.html
It has had a facelift recently, and is updated with new content including further configuration details of using WebSphere Application Server with the Spring Framework.
4 comments:
And? AND?
I prithee wouldst though deign to tell us how any of this applies to websphere? I see nothing in this post that was not cut and pasted from general Spring articles.
The purpose of my post was to highlight the revised content of the 'best practices' developerWorks article cited in the post (AOP, Annotations, JPA and EJB3, JMSTemplates) and provides code examples for people who like them.
The material was taken from that article, but as co-author of the article and lead of the team that tests Spring function on WebSphere I am eager to see people use Spring on WebSphere Application Server successfully and so felt a subset of that information would find a different audience in this format.
I apologise if it has irritated you. That was not my intention.
Nice article thanks,
I have one question as follows:
How can SpringFramework if possible use JTA from the application server container managed transaction, to be used along with Persistence layer?
Thanks,
http://www.interview-questions-tips-forum.net
"How can SpringFramework if possible use JTA from the application server container managed transaction, to be used along with Persistence layer?
"
Spring components are configured to use the underlying AppServer's JTA support as described in this post (and in the WAS InfoCenter). Under the covers, this causes the Spring container that processes the Spring application context to delegate to WAS transaction support and set up the appropriate transaction context - for example, if you configure your Spring bean with
tx:method name="set*" propagation="REQUIRES_NEW"
then that method will run under a new JTA transaction just the same as if you had deployed an EJB with a transaction attribute of RequresNew. In either case, any entity whose persistence is managed by a persistence f/w is accessed in the context of a WAS JTA transaction. So long as the persistence layer is configured for JTA, then it doesn't matter how WAS started the JTA transaction.
Post a Comment