title: JBoss 7.1 - declare datasource and access via JNDI
body: <p>I'am trying to migrate websphere 7  to JBoss 7.1 and i have several problem to configure my datasource, here is my whole config(database is oracle 10g) :</p>
  
  <p>Jboss deployement looks fine </p>
  
  <pre><code>JBAS010400: Bound data source [jboss/datasources/xx3_oracle_tu_2]
  </code></pre>
  
  <p>My standalone-full.xml :</p>
  
  <pre><code>&lt;datasources&gt;
         &lt;datasource jndi-name="java:jboss/datasources/xx3_oracle_tu_2" pool-name="xx3_oracle_tu_2" enabled="true" use-java-context="true"&gt;
                 &lt;connection-url&gt;jdbc:oracle:thin:@************:1521:*****&lt;/connection-url&gt;
                 &lt;driver&gt;oracle&lt;/driver&gt;
                 &lt;pool&gt;
                 &lt;/pool&gt;
                 &lt;security&gt;
                     &lt;user-name&gt;UD1XXBD&lt;/user-name&gt;
                     &lt;password&gt;*******&lt;/password&gt;
                 &lt;/security&gt;
             &lt;/datasource&gt;
      &lt;/datasources&gt;
      &lt;driver name="oracle" module="com.oracle.ojdbc"&gt;
          &lt;driver-class&gt;oracle.jdbc.OracleDriver&lt;/driver-class&gt;
      &lt;/driver&gt;
  </code></pre>
  
  <p>Seems ok about oracle driver:</p>
  
  <pre><code>JBAS010403: Deploying JDBC-compliant driver class oracle.jdbc.OracleDriver (version 1.0)
  </code></pre>
  
  <p>Here is my bean in spring xml file :</p>
  
  <pre><code>&lt;bean id="datasource" class="org.springframework.jndi.JndiObjectFactoryBean"&gt;
        &lt;property name="jndiName" value="java:jboss/datasources/xx3_oracle_tu_2"/&gt;
        &lt;property name="jndiEnvironment"&gt;
              &lt;props&gt;
                  &lt;prop key="java.naming.factory.initial"&gt;org.jboss.naming.remote.client.InitialContextFactory&lt;/prop&gt;
                  &lt;prop key="java.naming.provider.url"&gt;remote://localhost:4447&lt;/prop&gt;
                  &lt;prop key="java.naming.security.principal"&gt;user&lt;/prop&gt;
                  &lt;prop key="java.naming.security.credentials"&gt;******&lt;/prop&gt;
                  &lt;prop key="remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED"&gt;false&lt;/prop&gt;
                  &lt;prop key="java.naming.factory.url.pkgs"&gt;org.jboss.ejb.client.naming&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>The only error i have is : </p>
  
  <pre><code>Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: jboss/datasources/xx3_oracle_tu_2 -- service jboss.naming.context.java.jboss.exported.jboss.datasources.xx3_oracle_tu_2
  </code></pre>
  
  <p>On Jboss web admin console, no problems datasource appears.
  Also with jboss-cli script and this command line, everything seems ok :</p>
  
  <pre><code>jboss-cli.bat -c --command=/subsystem=datasources/data-source=xx3_oracle_tu_2:test-connection-in-pool
  {
      "outcome" =&gt; "success",
      "result" =&gt; [true]
  }
  </code></pre>
  
  <p>I don't understand why this command line does not work : </p>
  
  <pre><code>jboss-cli.bat -c --command=/subsystem=datasources/data-source=java\:jboss\/datasources\/xx3_oracle_tu_2:test-connection-in-pool
  </code></pre>
  
  <p>Am i missing something about JBoss 7.1 JNDI configuration ? </p>
  
  <p>Thanks by advance for your help !</p>
  
  <p>EDIT : don't declare jboss/datasources and declare it like this in your standalone file and jboss-web file:</p>
  
  <pre><code>java:/xx3_oracle_tu_2
  </code></pre>