无法通过JBoss远程访问数据源 [英] Unable to access datasource remotely through JBoss

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

问题描述

上下文

我有一个JBoss,我成功地部署了一个数据源 mydatasource-ds.xml
它的JNDI名称是 java:mydatasourceDS 。 JBoss声称数据源已成功部署。 JMX控制台也很好。

I have a JBoss where I have sucessfully deployed a datasource mydatasource-ds.xml. It's JNDI name is java:mydatasourceDS. JBoss claims that the datasource is succesfully deployed. The JMX console agress too.

问题

我想使用这个数据源来自在单独的JVM上启动的客户端Java应用程序。
但我得到一个例外,说无法找到 java:mydatasourceDS

I want to use this datasource from a client java app launched on a separate JVM. But I get an exception saying the java:mydatasourceDS cannot be found.

java.lang.ClassCastException: javax.naming.Reference cannot be cast to javax.sql.DataSource

详细信息

这是 persistence.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="mydatasource-db" transaction-type="JTA">
    <jta-data-source>java:mydatasourceDS</jta-data-source>
    <properties>
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.format_sql" value="true" />

        <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
        <property name="hibernate.hbm2ddl.auto" value="update" />
        <property name="hibernate.default_schema" value="rec" />

        <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
    </properties>
</persistence-unit>

这是 jndi.properties file:

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=jnp://localhost:1099
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

这是应用程序类路径:

jndi.properties
log4j.properties
META-INF\persistence.xml
hibernate-jpa-2.0-api-1.0.0.Final.jar
jnp-client-5.0.3.GA.jar
jboss-common-core-2.2.14.GA.jar
jboss-logging-spi-2.1.0.GA.jar
hibernate-entitymanager-3.6.4.Final.jar
hibernate-core-3.6.4.Final.jar
antlr-2.7.6.jar
commons-collections-3.1.jar
dom4j-1.6.1.jar
hibernate-commons-annotations-3.2.0.Final.jar
jta-1.1.jar
javassist-3.12.0.GA.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.6.1.jar
log4j-1.2.16.jar
xstream-1.4.1.jar
xmlpull-1.1.3.1.jar
xpp3_min-1.1.4c.jar

编辑
我找到了问题的根源。我的客户端应用程序可用的 javax.sql.DataSource 不是从JNDI收到的。我从JNDI收到的是JBoss javax.sql.DataSource 。相同名称但是稍微不同的类因此ClassCastException ...

EDIT I have found the source of the problem. The javax.sql.DataSource that was available to my client application was NOT the one received from JNDI. The one I receive from JNDI is the JBoss javax.sql.DataSource. Same name BUT slightly different classes hence the ClassCastException...

在撰写本文时,可以在此包中找到JBoss javax.sql.DataSource: jboss -j2ee-4.2.3.GA.jar

As of this writing, the JBoss javax.sql.DataSource can be found in this package : jboss-j2ee-4.2.3.GA.jar

推荐答案

本指南说明你需要设置

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

mydatasource-ds.xml 中。不确定你是否这样做。

in mydatasource-ds.xml. Not sure if you did.

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

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