3 Replies Latest reply on Nov 28, 2013 3:00 PM by wdfink

    Error lookup datasource jndi Spring Jboss 7

    rodrigo.parede

      Please help me!

       

      I started migrating jboss 4 to jboss 7.

       

      Error console:

      Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceJNDI' defined in ServletContext resource [/WEB-INF/cms-servlet.xml]: Invocation of init method failed; nested exception is javax.naming.NamingException: JBAS011843: Failed instantiate InitialContextFactory org.jnp.interfaces.NamingContextFactory from classloader ModuleClassLoader for Module "deployment.cms_motov2.war:main" from Service Module Loader

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338) [spring-2.5.6.SEC03.jar:2.5.6.SEC03]

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473) [spring-2.5.6.SEC03.jar:2.5.6.SEC03]

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) [spring-2.5.6.SEC03.jar:2.5.6.SEC03]

        at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.7.0_09]

        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) [spring-2.5.6.SEC03.jar:2.5.6.SEC03]

        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) [spring-2.5.6.SEC03.jar:2.5.6.SEC03]

        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) [spring-2.5.6.SEC03.jar:2.5.6.SEC03]

        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) [spring-2.5.6.SEC03.jar:2.5.6.SEC03]

        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) [spring-2.5.6.SEC03.jar:2.5.6.SEC03]

        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) [spring-2.5.6.SEC03.jar:2.5.6.SEC03]

        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269) [spring-2.5.6.SEC03.jar:2.5.6.SEC03]

       

      My configuration:

       

      cms-servlet.xml

      <bean id="dataSourceJNDI" class="org.springframework.jndi.JndiObjectFactoryBean">

        <property name="jndiName" value="java:jboss/datasources/myDS"/>

      </bean>

       

      jboss-web.xml

       

      <resource-ref>

              <res-ref-name>jdbc/myDS</res-ref-name>

              <res-type>javax.sql.DataSource</res-type>

              <jndi-name>java:jboss/datasources/myDS</jndi-name>

          </resource-ref>

       

      web.xml

       

      <resource-ref>

        <description>DB Connection</description>

        <res-ref-name>jdbc/myDS</res-ref-name>

        <res-type>javax.sql.DataSource</res-type>

        <res-auth>Container</res-auth>

      </resource-ref>

       

      standalone.xml

      <datasource jndi-name="java:jboss/datasources/myDS" pool-name="myDS" enabled="true" use-java-context="true">

                          <connection-url>jdbc:jtds:sqlserver://server/db;instance=SQLEXPRESS2008RC</connection-url>

                          <driver>mssql</driver>

                          <security>

                              <user-name>user</user-name>

                              <password>senha</password>

                          </security>

                      </datasource>

       

      I already tested the connection in jboss console, the problem must be the lookup in my project

        • 1. Re: Error lookup datasource jndi Spring Jboss 7
          wdfink

          From what I see you have a wrong property in your IC properties

               JBAS011843: Failed instantiate InitialContextFactory org.jnp.interfaces.NamingContextFactory

          The jnp protocol is not longer used in AS7.

           

          If you are somewhere inside the server you migth create 'only' a IC without any property. The container should do the rest and lookup that stuff local

          • 2. Re: Error lookup datasource jndi Spring Jboss 7
            rodrigo.parede

            Tks help, but not understand jnp protocol, can you help me?

            can be used for the spring 2.5?

            • 3. Re: Error lookup datasource jndi Spring Jboss 7
              wdfink

              I suppose you set the class org.jnp.interfaces.NamingContextFactory in the Properties for the InitialContext, maybe by using jndi.properties file.

              As this class does not exist for AS7 you need to change the properties.

              If you are inside the server you might create the IC without properties as the server know the datails and it should work.

              I don't know whether Spring can work in that way, but it is 'only' JNDI and there is no magic.