2 Replies Latest reply on Sep 8, 2015 11:24 AM by Paul Hinds

    spring 3.x + jboss 7.1.1: how to get the datasource from jndi

    settholo Newbie

      Hello everyone,

      I have to go into production with my web application. The application server is JBoss 7.1.1.

      So I was looking for moving the datasources from the spring application context to the container.

      I configured the datasource in jboss:

       

       

      <datasource jta="false" jndi-name="java:jboss/datasources/sampleDS" pool-name="sampleDSPool" enabled="true" use-java-context="true" use-ccm="false">
                          <connection-url>jdbc:postgresql://localhost:5432/sampleDB</connection-url>
                          <driver-class>org.postgresql.Driver</driver-class>
                          <driver>postgresql</driver>
                          <pool>
                              <min-pool-size>2</min-pool-size>
                              <max-pool-size>20</max-pool-size>
                          </pool>
                          <security>
                              <user-name>*****</user-name>
                              <password>*****</password>
                          </security>
                          <validation>
                              <validate-on-match>false</validate-on-match>
                              <background-validation>false</background-validation>
                              <background-validation-millis>1</background-validation-millis>
                          </validation>
                          <statement>
                              <prepared-statement-cache-size>0</prepared-statement-cache-size>
                              <share-prepared-statements>false</share-prepared-statements>
                          </statement>
                      </datasource>
      
      

       

       

      Well, when jboss starts it confirms that my datasource it's bound to java:jboss/datasources/sampleDS.

       

       

      Now I wanted to move the configuration:

       

       

      <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
                                    <property name="driverClassName" value="${db.driver.prod}" />
                                    <property name="url" value="${db.url.prod}" />
                                    <property name="username" value="${db.username.prod}" />
                                    <property name="password" value="${db.password.prod}" />
                          </bean>
      

       

       

       

      to

       

       

      <jee:jndi-lookup id="dataSource" jndi-name="java:jboss/datasources/sampleDS"/>
      

       

       

      or

       

       

      <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
                                    <property name="jndiName">
                                              <value>java:jboss/datasources/sampleDS</value>
                                    </property>
                          </bean>
      

       

       

      There is no way of getting the datasource from jboss, I always end with name not found ( I tried almost every combination ).

      Caused by: javax.naming.NameNotFoundException: jboss/datasources/sampleDS -- service jboss.naming.context.java.jboss.exported.jboss.datasources.sampleDS

      Is there someone that is able to use the datasource fomr joss through jndi?

       

      You can find the thread also in the spring forum at: http://forum.springsource.org/showthread.php?134298-spring-3-2-jboss-7-1-1-how-to-get-the-datasource-from-jndi


      Thank you for your help.

       

       

      Daniele