Announcement Announcement Module
Collapse
No announcement yet.
[Error] NameNotFoundException: jndi-lookup name is not associated with this context Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • [Error] NameNotFoundException: jndi-lookup name is not associated with this context

    Hi all,

    Trying to run the application into browser, the following error appears:

    javax.naming.NameNotFoundException: name hibernate/TFCappDS is not associated with this context
    I connect to data Source with JNDI lookup, my app server is VMware vFabric tc Server, and I'm using Hibernate as the ORM framwork.

    The fact is, I really don't know what name should I put as a jndi name.

    Furthermore, I read in some places that is necessary to define JNDI lookup name as a <resource> in server.xml file from Server directory, and then to reference JNDI from Server's web, in context.xml from the same directory. But I have no idea about how to create this server resource, or what values should I write considering my server and ORM cases (VMware vFabric tc Server, Hibernate)

    All my current code about JNDI and dataSource bean is this, at Spring xml file:

    Code:
    <jee:jndi-lookup id="dataSource"
    	jndi-name="hibernate/TFCappDS"
    	resource-ref="true"/>
    		
    <beans:bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    	<beans:property	name="dataSource" ref="dataSource"/>
    	<beans:property name="packagesToScan" value="cat.tfcproject.springmvc.domain"/>
    	<beans:property	name="hibernateProperties">
    	        <beans:props>
    		        <beans:prop key="dialect">org.hibernate.dialect.HSQLDialect</beans:prop>
    	        </beans:props>
    	</beans:property>
    </beans:bean>
    
    
    	
    <beans:bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
    	
    <beans:bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    	<beans:property name="sessionFactory" ref="sessionFactory"/> 
    </beans:bean>
    	
    <tx:annotation-driven transaction-manager="txManager"/>

    Someone know how to solve this?

  • #2
    There is a discussion of how to set up JNDI in tc Server here.

    [Found by googling: "tc server jndi configuration".]

    Comment


    • #3
      Thanks pfurbacher, but this thread did not help me very well. There must be a simple way and, directly from STS application and server explorer (not changing and creating files internally, outside the STS system developing)

      The case is, now I'm working with postgres so I only changed the SessionFactory dialect parameter, in servlet-context.xml:

      Code:
      <jee:jndi-lookup id="dataSource"
      	jndi-name="hibernate/TFCappDS"
      	resource-ref="true"/>
      		
      <beans:bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
      	<beans:property	name="dataSource" ref="dataSource"/>
      	<beans:property name="packagesToScan" value="cat.tfcproject.springmvc.domain"/>
      	<beans:property	name="hibernateProperties">
      	        <beans:props>
      		        <beans:prop key="dialect">org.hibernate.dialect.PostgreSQLDialect</beans:prop>
      	        </beans:props>
      	</beans:property>
      </beans:bean>
      
      
      	
      <beans:bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
      	
      <beans:bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
      	<beans:property name="sessionFactory" ref="sessionFactory"/> 
      </beans:bean>
      	
      <tx:annotation-driven transaction-manager="txManager"/>
      And I added the following resource, inside server.xml VMware tc Server file:

      Code:
      <GlobalNamingResources>
         	<Resource 	name="hibernate/TFCappDS"
         		auth="Container"
         		type="javax.sql.DataSource"
         		username="dbUsername"
         		password="dbPasswd"
         		driverClassName="org.postgresql.Driver"
         		url="jdbc:postgresql://localhost/TFCappDS"
         		maxActive="120"
         		maxIdle="5"
         		maxWait="5000"
         		initialSize="5"
         		poolPreparedStatements="true"
         		validationQuery="select 1" />	
          </GlobalNamingResources>
      But It still does not recognize jndi name as a part of this context.

      About this, I have two questions:

      Can someone tell me if I have the correct values of 'url' and 'driverClassName' parameters, considering postgres??

      Does Anyone know if there's something more to do, after editing servlet-context.xml and server.xml like this, to get JNDI-lookup name finally recognized? Or am I just simply wrong from de begining?


      Very grateful to everyone

      Comment


      • #4
        Hi bonetky, can you post a pic of your app server where you defined the resource?

        Comment


        • #5
          Do you mean a picture with the server directories? or the entire code of server.xml file where the resource is located? if second, there is no much more to see than the resource definition. I can post it this afternoon

          Comment


          • #6
            I have been playing with this for a while, trying to figure out what goes where. It turns out to be fairly simple, and the Tomcat 6/7 docs are relevant to this.

            Assuming that you have created a typical Web app project in STS/Eclipse, you'll have the following structure, to which I have added the folder, META-INF, and in that, the file context.xml, as shown below.

            Attachment

            The contents of the project's src/main/webapp/META-INF/context.xml file:

            Code:
            <?xml version="1.0" encoding="UTF-8"?>
            <Context>
            	<Resource 
            		name="hibernate/TFCappDS"
            		auth="Container"
            		type="javax.sql.DataSource"
            		username="dbUsername"
            		password="dbPasswd"
            		driverClassName="org.postgresql.Driver"
            		url="jdbc:postgresql://localhost/TFCappDS" 
            		...
            	/>
            </Context>
            That should do it. You may have to add the postgresql driver JAR to the tc Server's "lib" folder of the location specified in the -Dcatalina.base parameter in the launch configuration: double-click on your tc Server node in the "Servers" tab in STS, and then click the link "Open launch configuration" to view the parameter value. Geez, I hope that's clear; seems awfully long-winded to me. Just to be clear, here's an illustration of the link:

            Attachment


            You may also have to right-click on the tc Server node in the "Servers" tab and select "Clean tc working directory", or just "Clean...." Don't know for sure.

            But it doesn't seem to be as much work as outlined in the link I mentioned earlier, and it's pretty much what the Tomcat context documentation says should be done. I didn't even need to check "Publish module contexts to separate XML files."

            Good luck.

            [Added in editing:

            Note that a project like this will have a plethora of META-INF folders. Make sure you create the one I described and place the context.xml there.
            ]
            Attached Files

            Comment

            Working...
            X