|
|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV |
TOP LINKS YOU MUST CLICK ON Framework
Bringing Advanced Transaction Capabilities to Spring Applications
Inversion of control and dependency injection
Jul. 22, 2007 07:45 PM
Digg This!
Page 1 of 5
next page »
The Spring Framework provides a consistent abstraction for transaction management that delivers the following benefits:
This article discusses Spring's transaction management facilities and the common use cases in Spring where an external transaction manager is required. A real-world application is used to illustrate the transactional aspects and features. The focus is on leveraging JTA transaction management in the Spring Framework for enterprise applications. The article shows how Spring's transaction services can seamlessly expose and interact with a Java EE application server's transaction manager such as the Oracle Application Server and the OC4JJtaTransactionManager. A traditional bank account transfer application is used in this article to demonstrate basic Spring principles: the classic distributed two-phase commit-transaction use case requiring ACID properties; and Oracle's extended support for Spring with JTA using Spring's OC4JJtaTransactionManager. The transfer in the sample application is from a bank account to a brokerage account for the purchase individual stocks. It includes asset reporting to further illustrate particular transactional aspects and features. Let's start with an overview of the related technologies, Spring basics, transactioning basics, and transactioning features in Spring. Then we'll look at the implementation strategy and use the sample application to show in more detail how they all work together.
Spring Basics and Features Additionally, the Spring Framework can be integrated with different application servers such as Oracle Application Server, BEA WebLogic, and IBM WebSphere. Spring provides many features. Let's look at the following major areas in detail.
Inversion of Control Container and Dependency Injection
A main abstraction of inversion of control is the bean factory, which is a generic factory that retrieves objects by name and manages the relationships between objects. Dependency injection is a form of inversion of control that removes explicit dependence on container APIs. Ordinary Java methods are used to inject dependencies such as collaborating objects or configuration values into application object instances. Dependency injection is not a new concept, although it's only recently made prime time in the Java EE community. The definition of dependency injection between the J2EE community and the Spring Framework is the same, but obtained via different mechanisms.
XML Bean Definitions (ApplicationContext) The following example shows the configuration of the application objects, which is similar to the object relationships we are familiar with in J2EE applications. We will define a J2EE DataSource, bankDataSource; a DAO, bankDAO; and a business object that uses the DAO, assetManagementService. The following examples are from the sample bank account transfer application that shows the relationships between bankDataSource, bankDAO, and assetManagementService. First, let's look at the bankDataSource definition in XML format. As shown in the following example, we could use Spring's JNDI location FactoryBean to get the data source from the Oracle Application Server. (There would be no impact on Java code or any other bean definitions.)
<beans> Page 1 of 5 next page »
ENTERPRISE OPEN SOURCE MAGAZINE LATEST STORIES . . .
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||