Configure BTM with Spring to use Tomcat datasource

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Configure BTM with Spring to use Tomcat datasource

Hervé
Hello,
I am currently using BTM with Tomcat7/Spring4/MyBatis/HornetQ.
I successfully configured the transaction manager and it works.
Now, my problem is that the JDBC datasource is managed inside my aplication, and I am trying to put it in the Tomcat context.
Currently, my Spring configuration looks like:
<bean id="dataSource" class="bitronix.tm.resource.jdbc.PoolingDataSource" init-method="init" destroy-method="close">
        <property name="className" value="com.informix.jdbcx.IfxXADataSource" />
        <property name="uniqueName" value="uniqueName" />
        <property name="maxPoolSize" value="5" />
        <property name="driverProperties">
            <props>
                <prop key="user">${user}</prop>
                <prop key="password">${password}</prop>
                <prop key="serverName">${serverName}</prop>
                <prop key="databaseName">${database}</prop>
                <prop key="portNumber">${port}</prop>
                <prop key="ifxIFXHOST">${host}</prop>
                ...
            </props>
        </property>
    </bean>
I saw several posts to use Tomcat to declare objects but I don't understand how I can get it in my Spring context.

I am looking for a configuration like http://classnotfound.net/blog/2014/01/tomcat-datasource-configuration/ but is there a way to pass the datasource to the BTM?

If someone of you can help me on this point?
Thanks in advance
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Configure BTM with Spring to use Tomcat datasource

Brett Wooldridge-2


On Sat, Feb 15, 2014 at 11:37 PM, Hervé <[hidden email]> wrote:
Hello,
I am currently using BTM with Tomcat7/Spring4/MyBatis/HornetQ.
I successfully configured the transaction manager and it works.
Now, my problem is that the JDBC datasource is managed inside my aplication,
and I am trying to put it in the Tomcat context.
Currently, my Spring configuration looks like:

I saw several posts to use Tomcat to declare objects but I don't understand
how I can get it in my Spring context.

I am looking for a configuration like
http://classnotfound.net/blog/2014/01/tomcat-datasource-configuration/ but
is there a way to pass the datasource to the BTM?

If someone of you can help me on this point?
Thanks in advance



--
View this message in context: http://bitronix-transaction-manager.10986.n7.nabble.com/Configure-BTM-with-Spring-to-use-Tomcat-datasource-tp1605.html
Sent from the Bitronix Transaction Manager mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Configure BTM with Spring to use Tomcat datasource

Ludovic Orban-2
In reply to this post by Hervé
Setting up BTM as Tomcat's global transation manager is covered here: http://docs.codehaus.org/display/BTM/Tomcat2x
The doc speaks about Tomcat 6 but it's still valid for Tomcat 7.

Once that is done, you can use Spring's JndiObjectFactoryBean to access your datasources:

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/mydatasource" />
    <property name="resourceRef" value="true" />
</bean>

--
Ludovic

On Sat, Feb 15, 2014 at 3:37 PM, Hervé <[hidden email]> wrote:
Hello,
I am currently using BTM with Tomcat7/Spring4/MyBatis/HornetQ.
I successfully configured the transaction manager and it works.
Now, my problem is that the JDBC datasource is managed inside my aplication,
and I am trying to put it in the Tomcat context.
Currently, my Spring configuration looks like:

I saw several posts to use Tomcat to declare objects but I don't understand
how I can get it in my Spring context.

I am looking for a configuration like
http://classnotfound.net/blog/2014/01/tomcat-datasource-configuration/ but
is there a way to pass the datasource to the BTM?

If someone of you can help me on this point?
Thanks in advance



--
View this message in context: http://bitronix-transaction-manager.10986.n7.nabble.com/Configure-BTM-with-Spring-to-use-Tomcat-datasource-tp1605.html
Sent from the Bitronix Transaction Manager mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Configure BTM with Spring to use Tomcat datasource

Hervé
Thank you for the replies.
I used your link Ludovic, if I understand well, now, the datasource and the transaction manager are now created by Tomcat and put in the JNDI. Spring has to get the instances from the repository.
Correct me if I am wrong :)

Following my idea, I changed also the way of getting the transaction manager but now, I have this error:
nested exception is bitronix.tm.utils.InitializationException: cannot open disk journal

I saw a thread where it is mentioned that it happens when the BTM is started twice, but I don't understand how it is possible.
I checked my Spring config but it seems ok to me, if you can have a look (it is short):
    <tx:annotation-driven/>
    <tx:jta-transaction-manager/> 
<!-- commented because comes now from JNDI -->
    <!--  Bitronix Transaction Manager embedded configuration -->
<!--     <bean id="btmConfig" factory-method="getConfiguration" class="bitronix.tm.TransactionManagerServices"> -->
<!--         <property name="serverId" value="spring-btm" /> -->
<!--         <property name="DefaultTransactionTimeout" value="300" /> -->
<!--     </bean> -->
     
    <!-- create BTM transaction manager -->
<!--     <bean id="bitronixTransactionManager" factory-method="getTransactionManager" -->
<!--         class="bitronix.tm.TransactionManagerServices" depends-on="btmConfig" destroy-method="shutdown" /> -->
    
    <bean id="bitronixTransactionManager" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="java:comp/UserTransaction" />
        <property name="resourceRef" value="true" />
    </bean>
    
    <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" >
        <property name="transactionManager" ref="bitronixTransactionManager"/>
        <property name="userTransaction" ref="bitronixTransactionManager"/>
    </bean>

    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="jdbc/expElecCliDatasource" />
        <property name="resourceRef" value="true" />
    </bean>

Thanks
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Configure BTM with Spring to use Tomcat datasource

Hervé
Okay, finally, there was a problem in the name of the config files I passed to Tomcat, but unfortunately, it's still not working.
Checking in debug, I can see that the ResourceObjectFactory cannot get the datasource, I don't know how it should do that.
Currently, I have an exception lauched at:
Referenceable resource = ResourceRegistrar.get(uniqueName);
        if (resource == null)
            throw new NamingException("no resource registered with uniqueName '" + uniqueName + "', available resources: " + ResourceRegistrar.getResourcesUniqueNames());

I'm trying to find out where is the problem...
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Configure BTM with Spring to use Tomcat datasource

Ludovic Orban-2
Are you sure BTM has been properly integrated in Tomcat? When everything is done right, BTM logs that it's initializing during the Tomcat startup, and you also get an INFO log showing all your configured resources have been recovered. Make sure you get those logs and that all your JDBC datasources and JMS connection pools unique names appear in the recovery log.

I stongly recommend you to setup Tomcat *without your app deployed*, ie: perform the setup in a fresh Tomcat installation and make sure everything is working, eventually creating a simple webapp with a couple JSP's to test that you can get the UserTransaction and resources from JNDI. Once that is working, deploying your app should just make it work.

Another tip: make sure the BTM and JTA jars are *not* in your webapp's WEB-INF/lib folder. If you install BTM globally, the classes must come from Tomcat's classloader, not your app's one or you'll get all kind of strange errors.



On Sun, Feb 16, 2014 at 7:13 PM, Hervé <[hidden email]> wrote:
Okay, finally, there was a problem in the name of the config files I passed
to Tomcat, but unfortunately, it's still not working.
Checking in debug, I can see that the ResourceObjectFactory cannot get the
datasource, I don't know how it should do that.
Currently, I have an exception lauched at:


I'm trying to find out where is the problem...



--
View this message in context: http://bitronix-transaction-manager.10986.n7.nabble.com/Configure-BTM-with-Spring-to-use-Tomcat-datasource-tp1605p1609.html
Sent from the Bitronix Transaction Manager mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Configure BTM with Spring to use Tomcat datasource

Laurent Vaills
Hi Hervé,

Did you also configure the Bitronix listener in the server.xml file ?

Laurent


2014-02-16 20:43 GMT+01:00 Ludovic Orban <[hidden email]>:
Are you sure BTM has been properly integrated in Tomcat? When everything is done right, BTM logs that it's initializing during the Tomcat startup, and you also get an INFO log showing all your configured resources have been recovered. Make sure you get those logs and that all your JDBC datasources and JMS connection pools unique names appear in the recovery log.

I stongly recommend you to setup Tomcat *without your app deployed*, ie: perform the setup in a fresh Tomcat installation and make sure everything is working, eventually creating a simple webapp with a couple JSP's to test that you can get the UserTransaction and resources from JNDI. Once that is working, deploying your app should just make it work.

Another tip: make sure the BTM and JTA jars are *not* in your webapp's WEB-INF/lib folder. If you install BTM globally, the classes must come from Tomcat's classloader, not your app's one or you'll get all kind of strange errors.



On Sun, Feb 16, 2014 at 7:13 PM, Hervé <[hidden email]> wrote:
Okay, finally, there was a problem in the name of the config files I passed
to Tomcat, but unfortunately, it's still not working.
Checking in debug, I can see that the ResourceObjectFactory cannot get the
datasource, I don't know how it should do that.
Currently, I have an exception lauched at:


I'm trying to find out where is the problem...



--
View this message in context: http://bitronix-transaction-manager.10986.n7.nabble.com/Configure-BTM-with-Spring-to-use-Tomcat-datasource-tp1605p1609.html
Sent from the Bitronix Transaction Manager mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email




Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Configure BTM with Spring to use Tomcat datasource

Hervé
Hi,
I found the time to go back on this subject :-)

Finally, I found my error, it was just the name of the system property (for the config file) I used to start Tomcat which was wrong (shame on me ;) ).

Now, I have a ClassNotFoundException with JMS classes.
With this configuration for the Datasource, does it mean that all jars implied in the transaction management must be in the Tomcat lib directory, including JMS?

Currently, the JMS server (HornetQ) is embedded in my application, I'm affraid of that if it means that I have to put all the JMS stuff in Tomcat (queues creation and other factories).
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Configure BTM with Spring to use Tomcat datasource

Ludovic Orban-2
You are correct, you havet o put the JMS API jar as well as the HornetQ jars in Tomcat's lib folder. It's either that or embedding BTM in your web app and not integrating it into Tomcat at all.

This is a limitation of the JEE classloading model, there's nothing BTM can do about it.


On Mon, Feb 24, 2014 at 5:17 PM, Hervé <[hidden email]> wrote:
Hi,
I found the time to go back on this subject :-)

Finally, I found my error, it was just the name of the system property (for
the config file) I used to start Tomcat which was wrong (shame on me ;) ).

Now, I have a ClassNotFoundException with JMS classes.
With this configuration for the Datasource, does it mean that all jars
implied in the transaction management must be in the Tomcat lib directory,
including JMS?

Currently, the JMS server (HornetQ) is embedded in my application, I'm
affraid of that if it means that I have to put all the JMS stuff in Tomcat
(queues creation and other factories).




--
View this message in context: http://bitronix-transaction-manager.10986.n7.nabble.com/Configure-BTM-with-Spring-to-use-Tomcat-datasource-tp1605p1614.html
Sent from the Bitronix Transaction Manager mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Configure BTM with Spring to use Tomcat datasource

Hervé
Thank you for your help, Ludovic

I will now fight against HornetQ, now ;-)
--------------------------------------------
En date de : Mar 25.2.14, Ludovic Orban-2 [via Bitronix Transaction Manager] <[hidden email]> a écrit :

 Objet: Re: Configure BTM with Spring to use Tomcat datasource
 À: "Hervé" <[hidden email]>
 Date: Mardi 25 février 2014, 9h11
 
 
 
  You are correct, you havet o put the JMS API
 jar as well as the HornetQ jars in Tomcat's lib folder.
 It's either that or embedding BTM in your web app and
 not integrating it into Tomcat at all.
 
 
 This is a limitation of the JEE classloading model,
 there's nothing BTM can do about it.
 
 
 On Mon, Feb 24, 2014
 at 5:17 PM, Hervé <[hidden email]> wrote:
 
 Hi,
 
 I found the time to go back on this subject :-)
 
 
 
 Finally, I found my error, it was just the name of the
 system property (for
 
 the config file) I used to start Tomcat which was wrong
 (shame on me ;) ).
 
 
 
 Now, I have a ClassNotFoundException with JMS classes.
 
 With this configuration for the Datasource, does it mean
 that all jars
 
 implied in the transaction management must be in the Tomcat
 lib directory,
 
 including JMS?
 
 
 
 Currently, the JMS server (HornetQ) is embedded in my
 application, I'm
 
 affraid of that if it means that I have to put all the JMS
 stuff in Tomcat
 
 (queues creation and other factories).
 
 
 
 
 
 
 
 
 
 --
 
 View this message in context: http://bitronix-transaction-manager.10986.n7.nabble.com/Configure-BTM-with-Spring-to-use-Tomcat-datasource-tp1605p1614.html
 
 
 Sent from the Bitronix Transaction
 Manager mailing list archive at Nabble.com.
 
 
 
 ---------------------------------------------------------------------
 
 To unsubscribe from this list, please visit:
 
 
 
     http://xircles.codehaus.org/manage_email
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  If you reply to this email,
 your message will be added to the discussion below:
  http://bitronix-transaction-manager.10986.n7.nabble.com/Configure-BTM-with-Spring-to-use-Tomcat-datasource-tp1605p1615.html
 
 
 
  To unsubscribe from Configure BTM with Spring to use
 Tomcat datasource, click
 here.
  NAML
 
Loading...