Multiple application contexts causing JTA issues
I'm working on a web application that has somewhat of an interesting architecture. We have our own middleware/messaging layer which transports data via oagi bods (raw xml).
So my web app acts as a typical web app does, starts the application context via the ContextLoader servlet, but it also acts as a message consumer. This is where the issues come into play. I have a separate thread that is listening for any messages (bods) to be sent, if one is sent I need to call a method within a spring controlled class, so naturally I would need to provide some way to hook into the application context.
At first this seemed like an easy thing, BUT since this call is spawned via the listening thread (and not a web request) I don't have any access to pull the current application context out of the servlet context. First is there any easy way to do this? I could mimic a request and gain access to it that way, but that seems hokey and not the way to go. The other alternative is that I read the spring conifguration files and create another instance of the application context (via ClassPathXmlApplicationContext). This is the route I have taken, but have run into issues with the JTA jndi location. This is the error I get when attempting to start up the 2nd application context :
I think that this is since I have two spring application contexts open, which may be an absolute sin for all you J2EE purists out there :)
Initialization of bean failed; nested exception is org.springframework.transaction.TransactionSystemException: JTA UserTransaction is not available at JNDI location [java:comp/UserTransaction]; nested exception is javax.naming.NameNotFoundException: Name "comp/UserTransaction" not found in context "java:"
If anyone has any ideas that would be much appreciated.