Announcement Announcement Module
Collapse
No announcement yet.
Configure transaction manager for use with both JBoss and WebSphere Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Configure transaction manager for use with both JBoss and WebSphere

    Hi,

    I have a J2EE app that is required to run on both JBoss and WebSphere.

    I use REQUIRES_NEW in a certain piece of functionality and I am aware that you have to do something like the following to do this on WebSphere :

    <bean id="websphereTxManager"
    class="org.springframework.transaction.jta.WebSphe reTransactionManagerFactoryBean" />
    <bean id="myTransactionManager" class="org.springframework.transaction.jta.JtaTran sactionManager">
    <property name="transactionManager"><ref local="websphereTxManager"/></property>
    </bean>

    My question is does anyone know of an easy way to configure my transaction manager so I can use the same configuration file for both JBoss and WebSphere?

    Currently if I configure the websphere tx manager as above and run it on JBoss I get an exception saying it couldn't find the websphere tx manager (since we're running on JBoss)

    Thanks,
    Dave

  • #2
    You can put the TMs into separate files (with the same name but in different folders) and based on your development environment, make a script that ships the appropriate version.
    You can also add your own factoryBean which will try to detect a TM and in case it fails, try the second one.
    You can also use the JNDI location instead of relying on the WsTM (which uses the WsTM static methods to get a hold of the TM).

    Comment


    • #3
      Thanks for you suggestions.

      I think the factoryBean solution is the best, b/c its flexible. I haven't had to customize my build process between JBoss and WebSphere yet so I don't want to start now.

      Can you give me few a tips on how to create my own factory bean?

      Would I extend the spring JTATransactionManager and then override the setTransactionManager method and do the websphere vs. jboss check there?

      Or should I define my factory bean to return an instance of the websphere tx manager and then set spring's jta tx manager's 'transactionManager' property to accept my custom factory bean? I'm new to creating my own factory beans so any help you could give would be great.

      Thanks!

      Comment


      • #4
        Take a look at the javadoc of FactoryBean and the reference docs- it should be straight forward.

        The factoryBean would simply do lookup transaction1, if fails, lookup transaction2 and so on.
        Basically implement the InitializingBean interface and then manually instantiate the WebSphereTM and call afterPropertiesSet on it and then getObject() - if that works w/o an exception return it - if not then use a simple JtaTM to do the lookup in Jboss case.

        You could do the configuration from Spring but since the FactoryBean implement the InitializingBean interface, the init method will be called and an exception thrown. However, before coding this factory, check what's the location of the WebSphereTM inside JNDI - if it's the same as in JBoss you just have to get it from there.

        Comment


        • #5
          Ok, I found a solution.

          I ended up sub classing the spring JtaTransactionManager and I overrode the 'retrieveTransactionManager' method. The default implementation of this method in JtaTransactionManager returns null so in my overridden version I simply return null if I can't instantiate the WebsphereTransactionManagerFactoryBean.

          It works like a charm and was only a few lines of code

          Thanks for you ideas and help!

          Comment

          Working...
          X