问题配置JBoss以与JNDI(2)一起使用 [英] problem configure JBoss to work with JNDI(2)

查看:150
本文介绍了问题配置JBoss以与JNDI(2)一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继续上周的问题: 问题配置JBoss以与JNDI一起使用

我试图在JBoss中绑定数据源,并在我的应用程序中使用它.在我的挣扎中,我已经设法避免了javax.naming.NameNotFoundException,方法是:
1.在Java new InitialContext().lookup(connection);中使用
代替new JndiObjectFactoryBean().setJndiName(connection);
2.将连接名称从"jndi-name"更改为"java:jndi-name"

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'

现在的问题是,我从查询中获得的数据源为. 我创建了datsource文件:

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>

并将其放在\ server \ default \ deploy \ oracle-ds.xml
下 我在运行时得到以下信息:

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

18:37:56,560信息 [ConnectionFactoryBindingService] 绑定ConnectionManager'jb oss.jca:service = DataSourceBinding,name = bilby' 改为JNDI名称'java:bilby'

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

所以我的问题是-为什么我将null用作数据源?

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

推荐答案

首先,我只想确保您说的是

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

从以下位置更改连接名称: 'jndi-name'到'java:jndi-name'

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

您的意思是java:bilby,对吧?

我不确定具体为什么会发生这种情况,但是我可以建议一种解决方法.

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

<jndi-name>元素之后,将以下行添加到oracle-ds.xml中:

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

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

部署后,应从JNDI绑定中删除java:前缀.然后,您应该可以使用:

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")

并恢复您的DataSource.

这篇关于问题配置JBoss以与JNDI(2)一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆