Announcement Announcement Module
Collapse
No announcement yet.
Wiring a DataSource fails using JndiObjectFactoryBean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    James

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

    Comment


    • #3
      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

      Comment


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

        Comment


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

          Comment

          Working...
          X