Jetty JTA via JNDI with Spring

Published:
Tags:
Java Jetty JNDI Spring
Reading time:
About 1 min

Finally got Jetty 8 to have JTA transactions available to Spring via JNDI lookup using Atomikos 3.8 after a lot of trouble. I’m not 100% sure if this is correct but it seems to be working for me.

My main driver was not wanting to have Atomikos classes hardcoded in the spring config. Instead we can just register the Atomikos UserTransactionManager and UserTransactionImp classes in JNDI and have Spring look them up, just like if we were using Websphere, Weblogic, etc. Now I can use Jetty for local development instead of Websphere without any change to my actual code base. (Be warned that I’m not using this in prod.)

Steps:
1) Jetty 8 install
    Download, unzip, setup JETTY_HOME var for IntelliJ to use
2) Atomikos 3.8 install
    Download, unzip
    copy from the Atomikos lib/ directory into Jetty lib/ext/:
    geronimo-j2ee-connector_1.5_spec.jar
    geronimo-jms_1.1_spec.jar
    geronimo-jta_1.0.1B_spec.jar
    copy all the JARs from the Atomikos dist/ directory into Jetty lib/ext/.
    (Hat tip to this blogpost for helping)
3) Jetty config for JTA (Ref posting that helped)

4) Spring JTA lookup
    Spring will lookup using standard JNDI locations of java:/TransactionManager and java:comp/UserTransaction
    <tx:jta-transaction-manager/>