| By Debu Panda | Article Rating: |
|
| June 26, 2007 09:15 AM EDT | Reads: |
25,093 |
While building enterprise applications you probably want your business operations to be transactional. Next we'll see how you can use Spring declarative transactions and how Java EE containers provide the integration of Spring with their Transaction Manager.
Spring-Declarative TX and Integration with Application Server TM
Java EE provides a robust platform for building and deploying a transactional enterprise application. Java EE supports both programmatic and declarative transactions and unfortunately you can use declarative transactions only with EJB. Spring has robust support for declarative transactions and you can use the scheme with any POJO, adding declarative transaction capability to the Web container.
Let's assume that you want to define a declarative transaction for a method in a Spring bean. You have the following code:
@Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.READ_COMMITTED)
public Long addBid(Bid bid) {
..
}
When the addBid() method is invoked, Spring will automatically start a new transaction per our definition. The integration between Spring and the application server's transaction manager is what makes that possible.
Java EE containers such as Oracle Containers for Java EE (OC4J) provide integration between the transaction manager and Spring so that declarative transactions can be used. You can enable such integration with a simple setting:
!-- enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven/>
<bean id="transactionManager" class="org.springframework.transaction.jta.OC4JJtaTransactionManager">
The Manageability of Spring Components
While Spring components are easier to build and deploy in an application server, managing them may pose maintainability issues since Spring is a "foreign" framework. Application servers such as Oracle Application Server address this with interesting integration for managing Spring components.
For example, a Spring bean can be exposed in the MBean browser of Oracle's Application Server Control by making some minimal configuration changes in the Spring application context configuration. For example, we can register the Spring beans with the following Spring configuration:
<bean id="howToMBeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
<property name="defaultDomain" value="SpringHowTo" />
</bean>
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<map>
<entry key="bean:name=empService" value-ref="empService" />
<entry key="bean:name=employeeDAO" value-ref="employeeDAO" />
</map>
</property>
<property name="server" ref="howToMBeanServer" />
</bean>
The Spring beans appear as application-defined Managed Beans (MBean) in the MBean browser of application server's management console. e.g., OracleApplication Server Control's MBean browser as shown in Figure 1. Thus managing Spring components is a snap!
You can perform MBean operations on the Spring beans deployed as a part of your application
Conclusion
This concludes the second installment of the two-part article. In this article, we provided a series of examples to illustrate how Java EE 5 developers can exploit some common integration points with the Spring Framework. Specifically, we demonstrated how EJB 3.0 and JPA combine naturally with Spring, as well as demonstrated how Spring-based applications can utilize high-end Java EE container services such as database access and the JMS messaging infrastructure. Finally you learned how application servers provide management capability for Spring beans.
Published June 26, 2007 Reads 25,093
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Debu Panda
Debu Panda, lead author of the recently published EJB 3 in Action (Manning Publications), is a senior principal product manager on the Oracle Application Server development team, where he drives development of the Java EE container. He has more than 15 years of experience in the IT industry and has published numerous articles on enterprise Java technologies and has presented at many conferences. Debu maintains an active blog on enterprise Java at http://www.debupanda.com.
![]() |
jcl 11/24/09 01:16:00 PM EST | |||
Hi,thank you for this tutorial I'm interested on the first way to intregate Spring and EJB3. I have tried it in a example project buy it doesn't run. I'm searching since many time a solution,but nothing. I have posted on Spring forum,but no one seems can help me. I appreciate if you can help me.Thank you Antonio |
||||
- Kindle 2 vs Nook
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- Confessions of a Ulitzer Addict
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- It's the Java vs. C++ Shootout Revisited!
- Cloud Computing Can Revitalize Your Career as Software Developer
- IBM Could "Reinvent" Java: Mills
- Oracle & Cloud Computing: Exclusive Q&A with SVP Richard Sarwal
- A Brief History of Cloud Computing
- Kindle 2 vs Nook
- Cloud CEOs, CTOs & SVPs to Speak at 4th International Cloud Computing Expo
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing Expo: Exclusive Q&A with Yahoo! SVP Cloud Computing
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- A Cup of AJAX? Nay, Just Regular Java Please
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- The i-Technology Right Stuff
- JavaServer Faces (JSF) vs Struts
- Rich Internet Applications with Adobe Flex 2 and Java
- Java vs C++ "Shootout" Revisited
- Bean-Managed Persistence Using a Proxy List
- Reporting Made Easy with JasperReports and Hibernate
- Creating a Pet Store Application with JavaServer Faces, Spring, and Hibernate
- What's New in Eclipse?
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- i-Technology Predictions for 2007: Where's It All Headed?



































