Results 1 to 9 of 9

Thread: Mysql + Tomcat Datasource best practice

  1. #1
    Join Date
    Sep 2004
    Posts
    50

    Default Mysql + Tomcat Datasource best practice

    This is a very basic question but I cannot seem to find a definitive answer.

    What is the best way to configure a single datasource in Spring to a single mysql database (located on another machine) with tomcat.

    In my test setup I have mysql database running on the same machine and have just a standard datasource setup in my app-servlet.xml as follows:

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName"><value>com.mysql.jdbc.Drive r</value></property>
    <property name="url"><value>jdbc:mysql://localhost:3306/app</value></property>
    <property name="username"><value>user</value></property>
    <property name="password"><value>passwd</value></property>
    </bean>

    and it works fine.

    Will this be good enough for a production environment?

  2. #2
    Join Date
    Aug 2004
    Location
    Carlisle, UK
    Posts
    184

    Default

    If you find you have performance issues, you could try using a datasource with pooled connections.
    See http://forum.springframework.org/showthread.php?t=10772
    Last edited by robyn; May 14th, 2006 at 10:49 AM.
    Chris Harris
    Carlisle, UK

  3. #3
    Join Date
    Sep 2004
    Posts
    50

    Default

    Thanks Chris,

    This works fine also, I will probably use this on the production machine.

    I assume there is no need to configure the datasource external to the app-servlet.xml as was required in later versions of struts though (i.e. placing the database connection in $CATALINA_HOME/conf/server.xml).

  4. #4
    Join Date
    Aug 2004
    Location
    Carlisle, UK
    Posts
    184

    Default

    If you have the datasource configured in the app-servlet.xml, it will only be available to applications that have access to that spring context.
    If this one app is the only one that needs this datasource, that should be fine.

    I use jboss/tomcat, so I'm not familiar with the configuration of just tomcat. I'm guessing that 'placing the database connection in $CATALINA_HOME/conf/server.xml' makes it available to any tomcat app. If that's the case, it would depend on whether you need that functionality. And in that case, I don't know how you'd make a pooled datasource generally available.
    Chris Harris
    Carlisle, UK

  5. #5
    Join Date
    Sep 2004
    Posts
    50

    Default

    It's only required by this particular spring app.

    Thanks Chris

  6. #6
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    $CATALINA_HOME/conf/server.xml supports configuring both application level datasource (inside a <Context>) and server wide datasource (as a global resource)
    HTH
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  7. #7
    Join Date
    Sep 2004
    Posts
    50

    Default

    I am interested in reliability / performance, from this stand point, is there any disadvantage in setting the datasource up in the app-servlet.xml file.

  8. #8
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    I am interested in reliability / performance, from this stand point, is there any disadvantage in setting the datasource up in the app-servlet.xml file.
    You mean setting up a local datasource such as a Commons DBCP datasource, rather than a reference (also in your Spring application context) to a container-managed JNDI datasource?

    If you aren't using a full application server, but just a servlet engine like Tomcat, using a JNDI DataSource really buys you only consistent J2EE conventions for looking it up, and a container-wide place to define datasources. If you're using Spring you don't need to write the lookup code, so the first point doesn't matter much; the second one is no big deal either.

    In the case of a true app server, using a container datasource is necessary if you want global transactions managed using JTA (and driven by either EJB CMT, JTA usage or Spring transaction management).

    If you're not using JTA (and with Spring you don't need to unless you need transactions distributed across multiple transactional resources), there's no real reliability/performance advantage in using a datasource such as Commons DBCP configured fully in your Spring context. Commons DBCP does pool connections, as do C3PO, Proxol and other competing products.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  9. #9
    Join Date
    Sep 2004
    Posts
    50

    Default

    Thanks Rod, and everyone else who responded.

Similar Threads

  1. Replies: 4
    Last Post: Nov 24th, 2005, 02:38 AM
  2. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  3. Replies: 1
    Last Post: Aug 28th, 2005, 05:53 PM
  4. Odd behaviour when injecting TransactionTemplate
    By damon311 in forum Container
    Replies: 3
    Last Post: Jul 23rd, 2005, 11:21 AM
  5. Replies: 4
    Last Post: Jun 15th, 2005, 04:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •