JBoss 7.1-声明数据源并通过JNDI访问 [英] JBoss 7.1 - declare datasource and access via JNDI

查看:368
本文介绍了JBoss 7.1-声明数据源并通过JNDI访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Websphere 7迁移到JBoss 7.1,并且在配置数据源时遇到了几个问题,这是我的整个配置(数据库是oracle 10g):

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

Jboss部署看起来不错

Jboss deployement looks fine

JBAS010400: Bound data source [jboss/datasources/xx3_oracle_tu_2]

我的standalone-full.xml:

My standalone-full.xml :

<datasources>
       <datasource jndi-name="java:jboss/datasources/xx3_oracle_tu_2" pool-name="xx3_oracle_tu_2" enabled="true" use-java-context="true">
               <connection-url>jdbc:oracle:thin:@************:1521:*****</connection-url>
               <driver>oracle</driver>
               <pool>
               </pool>
               <security>
                   <user-name>UD1XXBD</user-name>
                   <password>*******</password>
               </security>
           </datasource>
    </datasources>
    <driver name="oracle" module="com.oracle.ojdbc">
        <driver-class>oracle.jdbc.OracleDriver</driver-class>
    </driver>

关于oracle驱动程序似乎没问题:

Seems ok about oracle driver:

JBAS010403: Deploying JDBC-compliant driver class oracle.jdbc.OracleDriver (version 1.0)

这是我在spring xml文件中的bean:

Here is my bean in spring xml file :

<bean id="datasource" class="org.springframework.jndi.JndiObjectFactoryBean">
      <property name="jndiName" value="java:jboss/datasources/xx3_oracle_tu_2"/>
      <property name="jndiEnvironment">
            <props>
                <prop key="java.naming.factory.initial">org.jboss.naming.remote.client.InitialContextFactory</prop>
                <prop key="java.naming.provider.url">remote://localhost:4447</prop>
                <prop key="java.naming.security.principal">user</prop>
                <prop key="java.naming.security.credentials">******</prop>
                <prop key="remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED">false</prop>
                <prop key="java.naming.factory.url.pkgs">org.jboss.ejb.client.naming</prop>
            </props>
        </property>
    </bean>

我唯一的错误是:

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

在Jboss Web管理控制台上,没有出现问题数据源. 同样,使用jboss-cli脚本和此命令行,一切似乎都还可以:

On Jboss web admin console, no problems datasource appears. Also with jboss-cli script and this command line, everything seems ok :

jboss-cli.bat -c --command=/subsystem=datasources/data-source=xx3_oracle_tu_2:test-connection-in-pool
{
    "outcome" => "success",
    "result" => [true]
}

我不明白为什么此命令行不起作用:

I don't understand why this command line does not work :

jboss-cli.bat -c --command=/subsystem=datasources/data-source=java\:jboss\/datasources\/xx3_oracle_tu_2:test-connection-in-pool

我是否缺少有关JBoss 7.1 JNDI配置的信息?

Am i missing something about JBoss 7.1 JNDI configuration ?

在此先感谢您的帮助!

不要在独立文件和jboss-web文件中声明jboss/datasources并像这样声明它:

EDIT : don't declare jboss/datasources and declare it like this in your standalone file and jboss-web file:

java:/xx3_oracle_tu_2

推荐答案

AFAIK该命令不接受完整的JNDI引用,它需要一个数据源名称.

AFAIK That command doesn't accept full JNDI references, it expects a datasource name.

您可以使用以下方式查看数据源名称

You can view your datasource names with

/subsystem=datasources:read-resource(recursive=true)

确定,所以您遇到的问题是远程查找.

ok, so the problem you have is with remote lookup.

如果您查看此线程,您会发现不幸的是:

If you look at this thread, you can see that unfortunately:

AS7不支持数据源的远程查找.

Remote lookup of datasources is not supported in AS7.

Edit2:所以您根本不需要进行远程查找.

so you're not doing a remote lookup after all.

这两者:

<jee:jndi-lookup id="datasource"
    jndi-name="java:jboss/datasources/xx3_oracle_tu_2"/>

和这个:

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

应该做.您不应该使用的JNDI env属性,该属性用于远程查找.

should do. JNDI env property you should not use, that's meant for remote lookups.

这篇关于JBoss 7.1-声明数据源并通过JNDI访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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