Results 1 to 7 of 7

Thread: Spring/hibernate/Tomcat error

  1. #1
    Join Date
    Sep 2004
    Location
    London
    Posts
    4

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Denver
    Posts
    249

    Default

    Try changing your JNDI name to:

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

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

    Default

    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.
    Omar Irbouh

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

  4. #4
    Join Date
    Sep 2004
    Location
    London
    Posts
    4

    Default

    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

  5. #5
    Join Date
    Aug 2004
    Location
    Ankara, Turkey
    Posts
    24

    Default

    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

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

    Default

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

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

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

  7. #7
    Join Date
    Sep 2004
    Location
    London
    Posts
    4

    Default

    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.

Similar Threads

  1. ERROR: Context initialization failed
    By makhlo in forum Architecture
    Replies: 8
    Last Post: Jul 11th, 2008, 01:41 AM
  2. Context initialization failed
    By kanonmicke in forum Container
    Replies: 7
    Last Post: Sep 29th, 2005, 12:35 AM
  3. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  4. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM
  5. Replies: 4
    Last Post: Nov 5th, 2004, 03:59 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
  •