Results 1 to 5 of 5

Thread: Wiring a DataSource fails using JndiObjectFactoryBean

  1. #1
    Join Date
    Dec 2004
    Location
    Asheville, NC
    Posts
    82

    Default Wiring a DataSource fails using JndiObjectFactoryBean

    I'm trying to configure my Spring MVC application to use connection pooling with a MySQL database. I have configured the DataSource in Tomcat 5.5.9 via a Context/Resource configuration which is included in my WAR as META-INF/context.xml. The file looks like this:
    Code:
    <Context>
    
        <Resource name="jdbc/MySqlDataSource"
                  auth="Container"
                  type="javax.sql.DataSource"
                  maxActive="100"
                  maxIdle="30"
                  maxWait="10000"
                  username="user"
                  password="mypassword"
                  driverClassName="com.mysql.jdbc.Driver"
                  url="jdbc&#58;mysql&#58;//localhost&#58;3306/ioifocus"
                  removeAbandoned="true" />
    
    </Context>
    If I only have this piece of the puzzle in place then my application starts up fine when I start Tomcat. However if I actually try to use this as my DataSource (instead of the DriverManagerDataSource I use for testing) then I get an error and the application fails to start. The only error message I get in the Tomcat log file is the cryptic "Error listenerStart":
    Code:
    Aug 8, 2005 9&#58;54&#58;18 AM org.apache.catalina.startup.HostConfig deployWAR
    INFO&#58; Deploying web application archive ioifocus.war
    Aug 8, 2005 9&#58;54&#58;20 AM org.apache.catalina.core.StandardContext start
    SEVERE&#58; Error listenerStart
    Aug 8, 2005 9&#58;54&#58;20 AM org.apache.catalina.core.StandardContext start
    SEVERE&#58; Context &#91;/ioifocus&#93; startup failed due to previous errors
    I have added the MySQL DataSource as a resource in my web.xml, like so:
    Code:
        <!--  JNDI Reference to the MySQL DataSource -->
        <resource-ref>
            <description>MySQL Database Connection</description>
            <res-ref-name>jdbc/MySqlDataSource</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
        </resource-ref>
    I am configuring the dataSource in my Spring configuration file like so:
    Code:
        <bean id="dataSource"
              class="org.springframework.jndi.JndiObjectFactoryBean">
            <property name="jndiName">
                <value>java&#58;comp/env/jdbc/MySqlDataSource</value>
            </property>
        </bean>
    The MySQL DBCP DataSource can be accessed from a JSP using <sql:query var="rs" dataSource="jdbc/MySqlDataSource">, so I'm pretty sure that it's configured correctly in Tomcat and the problem is with Spring not being able to wire it correctly using JNDI.

    I'm following the example from p. 256 of Harrop's "Pro Spring". I'm running Tomcat 5.5.9 on a Windows XP machine, and using Spring 1.2.3.

    Thanks in advance for any assistance!


    --James

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

    Default

    James

    Could you, please, turn logging to debug mode, and provide the error stackTrace?
    Omar Irbouh

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

  3. #3
    Join Date
    Dec 2004
    Location
    St. Gallen, Switzerland
    Posts
    69

    Default

    Hi,
    Im facing the same problem... has anybody an idea or a running example, how the peaces are put together?

    The environment is identical but i am using spring 1.2.6...

    Thanks and regards,
    Sandro

  4. #4
    Join Date
    Nov 2005
    Posts
    2

    Default

    Same error as well. Any ideas why? The only difference is that I don't get any errors in my logs.

  5. #5
    Join Date
    Nov 2005
    Posts
    2

    Default

    Found out that our connection pool was set to AutoCommit false and without a transaction manager the framework won't save anything.

Similar Threads

  1. Replies: 13
    Last Post: Feb 5th, 2010, 12:31 AM
  2. Replies: 1
    Last Post: Aug 18th, 2006, 11:04 PM
  3. JBoss DataSource not found
    By moacsjr in forum Data
    Replies: 10
    Last Post: Aug 25th, 2005, 01:26 PM
  4. Odd behaviour when injecting TransactionTemplate
    By damon311 in forum Container
    Replies: 3
    Last Post: Jul 23rd, 2005, 11:21 AM
  5. Ignoring missing Jndi DataSource within IDE?
    By Bill Pearce in forum Container
    Replies: 2
    Last Post: Oct 27th, 2004, 09:06 AM

Posting Permissions

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