Announcement Announcement Module
Collapse
No announcement yet.
Spring/hibernate/Tomcat error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring/hibernate/Tomcat error

    I understand that this is not a Spring problem, rather a problem I have configuring Tomcat (5.025) but it is stopping me using Spring and any help would be appreciated.

    I get the error:

    [org.springframework.web.context.ContextLoader] -
    <Context initialization failed>
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean wit
    h name 'cdDataSource' defined in resource [/WEB-INF/applicationContext.xml] of S
    ervletContext: Initialization of bean failed; nested exception is javax.naming.N
    ameNotFoundException: Name jdbc is not bound in this Context
    javax.naming.NameNotFoundException: Name jdbc is not bound in this Context

    I have seen suggested solutions to this problem, none of them seem to
    work.

    My web.xml:

    <resource-ref>
    <description>Oracle Datasource example</description>
    <res-ref-name>jdbc/cd_managerDB</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>

    My conf\Catalina\localhost\cd_manager.xml (cd_manager is app context):

    <Context path="/cd_manager" docBase="cd_manager" debug="1"
    reloadable="true">
    <ResourceLink global="jdbc/cd_managerDB"
    name="jdbc/cd_managerDB"/>
    <Resource name="jdbc/cd_managerDB"
    auth="Container" type="javax.sql.DataSource"/>

    <ResourceParams name="jdbc/cd_managerDB">
    <parameter>
    <name>factory</name>

    <value>org.apache.commons.dbcp.BasicDataSourceFact ory</value>

    </parameter>
    <parameter>
    <name>driverClassName</name>
    <value>oracle.jdbc.driver.OracleDriver</value>
    </parameter>
    <parameter>
    <name>url</name>
    <value>jdbc:oracle:thin:@localhost:1521pdb</value>
    </parameter>
    <parameter>
    <name>username</name>
    <value>cd_manager</value>
    </parameter>
    <parameter>
    <name>password</name>
    <value>password</value>
    </parameter>
    <parameter>
    <name>maxActive</name>
    <value>20</value>
    </parameter>
    <parameter>
    <name>maxIdle</name>
    <value>10</value>
    </parameter>
    <parameter>
    <name>maxWait</name>
    <value>-1</value>
    </parameter>
    </ResourceParams>
    </Context>

    applicationContext.xml:

    <bean id="cdDataSource"
    class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName">
    <value>jdbc/cd_managerDB</value>
    </property>
    </bean>

    Very grateful for any help received.

  • #2
    Try changing your JNDI name to:

    <property name="jndiName"><value>java:comp/env/jdbc/cd_managerDB</value></property>

    Comment


    • #3
      When looking for objects in jndi, you should either specify the full path:
      Code:
        <property name="jndiName"> 
          <value>java&#58;comp/env/jdbc/cd_managerDB</value> 
        </property>
      or ask Spring to do it for you by setting resourceRef to true:
      Code:
        <bean id="cdDataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> 
          <property name="jndiName"> 
            <value>jdbc/cd_managerDB</value> 
          </property> 
          <property name="resourceRef"> 
            <value>true</value> 
          </property> 
        </bean>
      HTH.

      Comment


      • #4
        Thanks for the help guys. Unfortunately not working still. I can see from debug that the correct jndi name is being used. Must be something fundamental in my tomcat config.

        Cheers,

        Ben

        Comment


        • #5
          I am also using Tomcat 5.0.25, and had a similar problem before. Now I don't have the problem, and my definition is like this, you can try it:

          (This is in TOMCAT\conf\server.xml, not in another file)
          Code:
          	<Context path="/cd_manager" docBase="cd_manager" debug="1" 
          reloadable="true"> 
          
                <Resource auth="Container" name="jdbc/cd_managerDB" type="javax.sql.DataSource"/>
          
          	<ResourceParams name="jdbc/cd_managerDB">
          ...........
          ...........
          The rest is the same in your post.
          HTH,
          Turgay Zengin

          Comment


          • #6
            A user had a "simillar" configuration problem Tomcat + Spring + Hibernate configuration problem

            HTH
            Last edited by Rod Johnson; Jan 18th, 2006, 10:31 AM.

            Comment


            • #7
              thanks awfully for the help chaps.

              Just to kill this thread off, the prob was that I had:

              Code:
               <ResourceLink global="jdbc/cd_managerDB" name="jdbc/cd_managerDB"/>
              in my context.xml but my datasource is not defined as a global resource. Removing this has solved the problem.

              Comment

              Working...
              X