Announcement Announcement Module
Collapse
No announcement yet.
JNDI Datasource not found in JBoss 4.2.3 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JNDI Datasource not found in JBoss 4.2.3

    Hi,

    I've a problem with using the JNDI Datasource with JBoss 4.2.3. I always get an error like:
    Code:
    10:03:06,131 INFO  [STDOUT] 10:03:06,131 ERROR ContextLoader:204 - Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Invocation of init method failed; neste
    d exception is javax.naming.NameNotFoundException: JNDI object with [java:csiDS] not found: JNDI implementation returned null
    Caused by: javax.naming.NameNotFoundException: JNDI object with [java:csiDS] not found: JNDI implementation returned null
            at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:125)
            at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:85)
            at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:121)
            at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:146)
            at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:93)
            at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
            at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:197)
            at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:184)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory
    .java:1198)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.ja
    va:1167)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:4
    27)
            at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)
            at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:285
    )
            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
            at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:245)
            at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:188)
            at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
            at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3856)
            at org.apache.catalina.core.StandardContext.start(StandardContext.java:4361)
            at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:790)
            at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:770)
            at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:553)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:585)
            at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:296)
    ...
    csi-ds.xml
    Code:
    <datasources>
       <local-tx-datasource>
    
          <jndi-name>csiDS</jndi-name>
    
          <connection-url>jdbc:postgresql://localhost/prototyping</connection-url>
    
          <driver-class>org.postgresql.Driver</driver-class>
    
          <user-name>prototyping</user-name>
          <password>prototyping</password>
    
          <min-pool-size>5</min-pool-size>
    
          <max-pool-size>20</max-pool-size>
    
       </local-tx-datasource>
       
    </datasources>
    applicationContext.xml (tried als with starting "/", but same effect):
    Code:
    ...
    <jee:jndi-lookup id="dataSource" jndi-name="java:csiDS"/>
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    		<property name="dataSource" ref="dataSource"/>
    		<property name="persistenceUnitName" value="csi" />
    		<property name="jpaVendorAdapter" ref="jpaAdapter"/>
    		<property name="jpaProperties">
    			<props>
    					<prop key="show_sql">true</prop>
    					<prop key="hibernate.current_session_context_class">jta</prop>
    					<prop key="hibernate.session_factory_name">csiSessionFactory</prop>
    					<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</prop>
    					<prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</prop>
    			</props>
    		</property>  
    	</bean>
            <bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                    <property name="database">
                    	<value>${jpa.database}</value>
                    </property>
                    <property name="showSql">
                    	<value>${hibernate.show_sql}</value>
                    </property>
                </bean>
    <tx:annotation-driven transaction-manager="transactionManager" />
    ...
    persistence.xml:
    Code:
    <persistence xmlns="http://java.sun.com/xml/ns/persistence"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
       <persistence-unit name="csi">
       	   <jta-data-source>java:csiDS</jta-data-source>
           <properties>
              <!-- <property name="hibernate.hbm2ddl.auto" value="update"/> -->
              <property name="hibernate.default_schema" value="csi"/>
              <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
           </properties>
       </persistence-unit>
    </persistence>
    Using Libs from JBoss AS 4.2.3 and additional libs:
    --
    => WEB-INF/lib (not in Build Path)
    c3p0-0.9.1.2.jar
    commons-beanutils-1.6.jar
    commons-collections-3.2.jar
    commons-digester-1.8.jar
    commons-lang-2.3.jar
    commons-logging-1.0.4.jar
    commons-validator-1.3.0.jar
    dom4j-1.6.1.jar
    freemarker-2.3.8.jar
    jboss-archive-browsing.jar
    jsonplugin-0.30.jar
    jsr173_api.jar
    ognl-2.6.11.jar
    postgresql-8.1-405.jdbc3.jar
    slf4j-api-1.5.2.jar
    slf4j-log4j12-1.5.2.jar
    struts2-spring-plugin-2.0.11.1.jar
    tiles-api-2.0.4.jar
    tiles-core-2.0.4.jar
    tiles-jsp-2.0.4.jar
    --
    => WEB-INF/lib (in Build Path)
    jettison-1.0-RC1.jar
    log4j-1.2.15.jar
    spring.jar
    xstream-1.2.2.jar
    xwork-2.0.4.jar
    groovy-1.5.7.jar
    jmesa-2.3.4.jar
    ldapjdk.jar
    struts2-core-2.0.11.1.jar

    Anybody has a hint what I'm doing wrong?

    Kind regards,
    Michael

  • #2
    The JBoss seems to make JNDI complex. I faced similar problem which I got rid by making some configuration.

    Configuration 1: In XXX-ds.xml file that you put in your JBoss server, put this XML tag:

    Code:
    <use-java-context>false</use-java-context>
    Then in your spring configuration file, use following
    Code:
    <jee:jndi-lookup id="gsxDataSource" jndi-name="YOUR_JNDI_NAME" resource-ref="false" />
    I hope this helps.

    Thanks,
    Niranjan

    Comment


    • #3
      Cool. Your configuration works, thx. Can you tell me why I have to kill the java-context "java:" in the JNDI name? Has this any side effects?

      Cheers,
      Michael

      Comment


      • #4
        Looks like I was a little to early. Read access on the datasource works (see some select statements in the logger), but if I try to insert or update data, nothing happens, also no error is given :-(.

        I think it has s.th. to do with the JTA. Any hint what I've missed?

        applicationContext.xml:
        Code:
        <?xml version="1.0" encoding="UTF-8"?>
        <!--  This is the Spring configuration file.  This file declares all of the Spring beans that
        			will be used by the Struts 2 Minimal.
        -->
        <beans xmlns="http://www.springframework.org/schema/beans"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:tx="http://www.springframework.org/schema/tx"
            xmlns:jee="http://www.springframework.org/schema/jee"
            xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
            http://www.springframework.org/schema/jee
            http://www.springframework.org/schema/jee/spring-jee-2.0.xsd">
        
        	<jee:jndi-lookup id="dataSource" jndi-name="csiDS" resource-ref="false" />
        
        	<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
        
        	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        		<property name="dataSource" ref="dataSource"/>
        		<property name="persistenceUnitName" value="csi" />
        		<property name="jpaVendorAdapter" ref="jpaAdapter"/>
        		<property name="jpaProperties">
        			<props>
        					<prop key="show_sql">true</prop>
        					<prop key="hibernate.current_session_context_class">jta</prop>
        					<prop key="hibernate.session_factory_name">csiSessionFactory</prop>
        					<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</prop>
        					<prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</prop>
        			</props>
        		</property>  
        	</bean>
        	
            <bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            	<property name="database">
                	<value>${jpa.database}</value>
            	</property>
            	<property name="showSql">
                	<value>${hibernate.show_sql}</value>
            	</property>
            </bean>
            
        	<bean id="transactionManager"  class="org.springframework.transaction.jta.JtaTransactionManager">
         		<property name="userTransactionName">
         			<value>UserTransaction</value>
         		</property>
        	</bean>
        	
            <tx:annotation-driven transaction-manager="transactionManager" />
        
        	<import resource="app-bean-configuration.xml" />
           
        </beans>
        Last edited by praenti; Apr 15th, 2009, 02:59 AM.

        Comment


        • #5
          Well, as per Java EE spec, every app server provides the java: context for JNDI. To access such JNDI names, you have to provide "java:comp...". JBoss maintains a global JNDI context, where you do not need to give this "java:" context. Using <use-java-context> to "false", JBoss allows the JNDI to bound to its global JNDI context and you can access the JNDI without any "java" context.

          I might not be fully correct, but in JBoss, whenever I try to access a JNDI using "java" context, I always get "NameNotFoundException". Also, this configuration is mentioned in JBoss WIKI. So, its genuine although my concept is not fully correct .

          For your other INSERT/UPDATE problem, its nothing to do with this JNDI configuration. If you are getting the DB connection, your JNDI works. I have not worked much in JPA (although I have worked in Hibernate), but it seems, you have to attach some transaction boundary to each INSERT/UPDATE statement. Check your transaction demarcations.

          Cheers,
          Niranjan
          Last edited by nnanda; Apr 16th, 2009, 02:48 AM.

          Comment

          Working...
          X