problem configure JBoss to work with JNDI(2)

自闭症网瘾萝莉.ら 提交于 2020-01-14 13:58:11

问题


in continuation to the question from last week: problem configure JBoss to work with JNDI

I'm trying to bind datasource in JBoss and use it in my application. In my struggling, I already managed to avoid the javax.naming.NameNotFoundException by:
1. using in java new InitialContext().lookup(connection);
instead of new JndiObjectFactoryBean().setJndiName(connection);
2. changing the connection name from: 'jndi-name' to 'java:jndi-name'

Now the problem is that the datasouce that I get from the lookup is null. I created the datsource file:

 <datasources>  
   <local-tx-datasource>
    <jndi-name>bilby</jndi-name>
    <connection-url>jdbc:oracle:myURL</connection-url>
    <driver-class>oracle.jdbc.OracleDriver </driver-class>
    <user-name>myUsername</user-name>
    <password>myPassword</password>        
    <exception-sorter-class- name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>

            <metadata>
         <type-mapping>Oracle9i</type-mapping>
      </metadata>   
</local-tx-datasource>

</datasources>

and put it under \server\default\deploy\oracle-ds.xml
I get during runtime the line:

18:37:56,560 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jb oss.jca:service=DataSourceBinding,name=bilby' to JNDI name 'java:bilby'

So my question is - why do I get null as my datasource???


回答1:


Firstly, I just want to make sure that when you said

changing the connection name from: 'jndi-name' to 'java:jndi-name'

that you really meant java:bilby, right?

I'm not sure specifically why this is happening, but I can suggest a workaround.

Add the following line to your oracle-ds.xml, after the <jndi-name> element:

<use-java-context>false</use-java-context>

When this is deployed, it should remove the java: prefix from the JNDI binding. You should then be able to use:

new InitialContext().lookup("bilby")

and get your DataSource back.




回答2:


First of all, I suggest looking at the samples available in JBOSS_DIST/docs/examples/jca for all configuration options (including pool sizing parameters).

Secondly, I did a quick test with the default datasource configured in hsqldb-ds.xml which is defined as follow:

<datasources>
   <local-tx-datasource>

      <!-- The jndi name of the DataSource, it is prefixed with java:/ -->
      <!-- Datasources are not available outside the virtual machine -->
      <jndi-name>DefaultDS</jndi-name>

      ...

</datasource>

And the following lookup just works:

DataSource ds = null;
Connection conn = null;
try {
    ds = (DataSource) new InitialContext().lookup("java:/DefaultDS");
    conn = ds.getConnection();
    // ...
    conn.close();
} catch (Exception e) {
    // handle me
}

If this doesn't for you, maybe clarify what you are passing to the lookup method exactly.



来源:https://stackoverflow.com/questions/2843218/problem-configure-jboss-to-work-with-jndi2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!