Atomikos Forum |
|
Hello,
I'd like to know if it's possible to know: How to define a 'com.atomikos.icatch.jta.UserTransactionManager' (instead of UserTransactionImp/com.atomikos.icatch.jta.UserTransactionFactory) within TomCat (context)??! Thnx a lot in advance,
I hope i do understand your question right - you want to define a UserTransactionManager per Webapp Context - right - and do this via Tomcat stuff and not via Spring for example.
If this was your question than the answer would be - use a LifeCycleListener and create the TxManager there. http://tomcat.apache.org/tomcat-6.0-doc/config/context.html#Lifecycle_Listeners You can instantiate your Manager there and export it via JNDI for example - look at the NamingContextListener as an example. I did not write any glue code yet for this (me ist using spring) but this should work in theory ;-). Tell if this is not what you asked or you need some code.
Hi Torsten,
It´s a good/interesting tip of "use a LifeCycleListener and ..." But, I'm satisfied using a single TransactionManager shared by all transactions and all Webapp (since it works properly, off course). Anyway, thnx a lot!! The point is that need/want retrieve, in my App (spring), the (single) TransactionManager (not a UserTransaction), defined in Container, via JNDI, get it?! The approach is the following: to fetch the Container TransactionManager by way of JNDI lookUp (Important: it has to be of the class 'atomikos.icatch.jta.UserTransactionManager'; an object of the class 'atomikos.icatch.jta.UserTransactionImp' is not enough unfortunetaly); defining a 'springframework.transaction.jta.JtaTransactionManager' bean injecting the TransactionManager on property 'transactionManagerName', and state autodetectUserTransaction=true this way: <!-- JTA Transaction Manager este setting p/ ser usada em Produção: Container Java.--> <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="transactionManagerName" value="java:comp/TransactionManager"></property> <property name="autodetectUserTransaction" value="true"></property> </bean> So I'm gonna remake my ask/question in a more clealy way: I also would like to "mock" this behavior/setUp in a Test enviroment. Using a Spring setting like the above, I used to ReBind a naming.Reference of 'UserTransactionImp' in a JUnit Test, this way: Reference atomikosUserTransactionFactoryDS = new Reference("com.atomikos.icatch.jta.UserTransactionImp" , "com.atomikos.icatch.jta.UserTransactionFactory", null); atomikosUserTransactionFactoryDS .add(new RefAddr("name") { public Object getContent() { return "UserTransaction"; } } ); atomikosUserTransactionFactoryDS .add(new RefAddr("type") { public Object getContent() { return "com.atomikos.icatch.jta.UserTransactionImp"; } } ); rgstrIniCtx.rebind("java:comp/UserTransaction", atomikosUserTransactionFactoryDS); //utm initContext So, the point is: Isn't there means to make a naming.Reference of an object of the class 'UserTransactionManager' (i.e. a object TransactionManager implementation) and ReBind it in JNDI by "java:comp/TransactionManager"??"
Should be possible with a LifeCycleListener too like mentioned there:
http://www.atomikos.com/Documentation/Tomcat55Integration33 There the listener is already used to create the TxManager - modify this one and add the code to bind and unbind this created instance at JNDI naming context on start/stop event. HTH
@Torsten,
Ok! Now I'm more safe about a instance of (User)TransactionManager be created within the Java Container (TomCat); and Spring Callback smart the enough to get TransactionManager in JNDI even if it bound w/ the "java:comp/UserTransaction" naminig! thank u very much! ;-)) @Guy Pardon, In the case I use Tomcat 6 (or even 7)??! Do we still have to put/keep the 'Lifecycle .JAR' in TOMCAT_HOME/lib directory??! And for version 6.x+: plz, just confirm to me if the correct .JAR is "atomikos-lifecycle-listener.jar" (instead of atomikos-tomcat-lifecycle.jar)??! |