How to use Global Transactions and Data Sources with Spring Framework 2.0.8 in SAP Netweaver Aplication Server 7.0, Part 1
For this part, we will create, build and deploy a J2EE Application on SAP AS 7.0 with J2SE 1.4, and the version of Spring Framework is 2.0.8 because it is the last one that can be supported by J2SE 1.4.
For the Spring XML configuration we will use the XML configuration syntax based on XML Schema, also we could use syntax based on XML DTD for backward compatibility. Because of we are using J2SE 1.4, we will need a parser that supports XML Schema like Xerces.
We need to remind that when you create an application with transaction support, we could use 2 type of transaction:
- Local Transaction are resource-specific (by example when only we work with one resource that needs transaction support like jdbc connection).
- Global Transaction are managed by the application server using JTA, it provide the ability to work with multiple transactional resources (by example when we work atleast two resources that need transaction support like jdbc connection, and jca connection).
1. Create a Java Project and add the Spring Libraries and its dependence libraries, and Xerces library too. Here, we will create the Spring XML Configuration file like Figure 1.
Figure 1 |
Here, we are using the new Spring AOP Tags to use transaction in our application. The most important thing related to this blog is the transaction-manager attribute of the tx:advice tag.
2. We will create the Spring bean to control the transaction. It is the transaction manager bean like the figure 2.
Figure 2 |
In this part, we are using the default name for the transaction manager bean. Also, we are declaring 2 properties: userTransactionName and transactionManagerName.
The default JNDI location for the JTA UserTransaction is java:comp/UserTransaction, but in the SAP AS the JNDI Name for it is "UserTransaction", it is reason because we will use it on the userTransactionName property of the "transactionManager" Spring bean. The other property, transactionManagerName, is necessary for suspending and resuming transactions, as this not supported by the UserTransaction interface. The TransactionManager will be autodetected if the JTA UserTransaction object implements the JTA TransactionManager interface too, but how we don't know the exactly implementation of the JTA UserTransaction interface, it is better to use the right JNDI value on the SAP AS ("ts").
This Spring bean "transactionManager" is used in the advice with id "myServiceTxAdvice". It give us the posibility to use global transactions in our code. It together with pointcut named "serviceOperation" allows to wrap every method on the class MyService that follow the expression "execution(* *..service.MyService.*(..))".
The Spring XML configuration file could be used in Spring MVC proyect, or Java project with some class to load the Spring Xml file (by example using the org.springframework.context.support.ClassPathXmlApplicationContext class as Figure 3).
Figure 3 |
The next part of this blog we learn about how to use J2EE Data sources on J2EE Application with Spring Framework on SAP AS 7.0
Comments