context.lookup(“datasource”)返回org.jboss.jca.adapters.jdbc.WrapperDataSource

时间:2013-10-24 07:13:08

标签: java jdbc jboss datasource wildfly

我正在处理需要在 weblogic jboss 上部署的项目。我从源代码编译了 wildfly 。现在,我正在尝试使用命名获取数据源。应用程序在 JBOSS EAP 6.1 上正常运行,我能够将数据源引用为javax.sql.DataSource,但现在使用以下代码> widlfly

dataSource = (javax.sql.DataSource) context.lookup("datasource");

它抛出异常

java.lang.ClassCastException: org.jboss.jca.adapters.jdbc.WrapperDataSource cannot be cast to javax.sql.DataSource

如果我尝试使用以下代码,

Object obj = context.lookup("datasource");
dataSource = (javax.sql.DataSource) obj;

它不会抛出上述异常,而是使用数据源,它会抛出异常

Caused by: java.lang.IncompatibleClassChangeError: Class org.jboss.jca.adapters.jdbc.WrapperDataSource does not implement the requested interface javax.sql.DataSource

但是,查看类的代码,我们可以看到它实现了javax.sql.DataSource

任何人都可以告诉我如何使用已转换的WrapperDataSource或将数据源作为javax.sql.DataSource返回。

服务器信息:

Calling "C:\wildfly-8.0.0.Beta2-SNAPSHOT\bin\standalone.conf.bat"
Setting JAVA property to "C:\Progra~2\Java\jdk1.7.0_40\bin\java"
===============================================================================

  JBoss Bootstrap Environment

  JBOSS_HOME: "C:\wildfly-8.0.0.Beta2-SNAPSHOT"

  JAVA: "C:\Progra~2\Java\jdk1.7.0_40\bin\java"

===============================================================================

Listening for transport dt_socket at address: 8787
16:04:19,731 INFO  [org.jboss.modules] (main) JBoss Modules version 1.3.0.Final
16:04:19,903 INFO  [org.jboss.msc] (main) JBoss MSC version 1.2.0.Beta2
16:04:19,997 INFO  [org.jboss.as] (MSC service thread 1-6) JBAS015899: WildFly 8.0.0.Beta2-SNAPSHOT "WildFly" starting
16:04:21,138 INFO  [org.jboss.as.server] (Controller Boot Thread) JBAS015888: Creating http management service using socket-binding (management-http)
16:04:21,138 INFO  [org.xnio] (MSC service thread 1-1) XNIO version 3.1.0.CR7
16:04:21,153 INFO  [org.xnio.nio] (MSC service thread 1-1) XNIO NIO Implementation Version 3.1.0.CR7
16:04:21,309 INFO  [org.jboss.remoting] (MSC service thread 1-1) JBoss Remoting version 4.0.0.Beta1
16:04:21,341 INFO  [org.jboss.as.webservices] (ServerService Thread Pool -- 50) JBAS015537: Activating WebServices Extension
16:04:21,356 INFO  [org.jboss.as.security] (ServerService Thread Pool -- 46) JBAS013171: Activating Security Subsystem
16:04:21,372 INFO  [org.jboss.as.security] (MSC service thread 1-8) JBAS013170: Current PicketBox version=4.0.19.Final
16:04:21,388 INFO  [org.jboss.as.naming] (ServerService Thread Pool -- 41) JBAS011800: Activating Naming Subsystem
16:04:21,388 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 33) JBAS010280: Activating Infinispan subsystem.
16:04:21,388 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-3) JBAS017502: Undertow 1.0.0.Beta18 starting
16:04:21,403 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 49) JBAS017502: Undertow 1.0.0.Beta18 starting
16:04:21,403 INFO  [org.jboss.as.jsf] (ServerService Thread Pool -- 39) JBAS012605: Activated the following JSF Implementations: [main]
16:04:21,419 INFO  [org.jboss.as.connector.logging] (MSC service thread 1-7) JBAS010408: Starting JCA Subsystem (IronJacamar 1.1.0.Final)
16:04:21,450 INFO  [org.jboss.as.naming] (MSC service thread 1-3) JBAS011802: Starting Naming Service
16:04:21,466 INFO  [org.jboss.as.mail.extension] (MSC service thread 1-7) JBAS015400: Bound mail session [java:jboss/mail/Default]
16:04:21,466 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 28) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
16:04:21,481 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) JBAS010417: Started Driver service with driver-name = h2
16:04:21,559 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 49) JBAS017527: Creating file handler for path C:\wildfly-8.0.0.Beta2-SNAPSHOT/welcome-content
16:04:21,700 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-6) JBAS017525: Started server default-server.
16:04:21,700 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-4) JBAS017531: Host default-host starting
16:04:21,763 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-6) JBAS017519: Undertow HTTP listener default listening on localhost/127.0.0.1:8080
16:04:21,841 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 28) JBAS010403: Deploying JDBC-compliant driver class com.ibm.db2.jcc.DB2Driver (version 3.57)
16:04:21,841 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-1) JBAS010417: Started Driver service with driver-name = DB2Driver
16:04:22,091 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-5) JBAS015012: Started FileSystemDeploymentService for directory C:\wildfly-8.0.0.Beta2-SNAPSHOT\standalone\deployments
16:04:22,091 INFO  [org.jboss.as.remoting] (MSC service thread 1-1) JBAS017100: Listening on 127.0.0.1:9999
16:04:22,122 INFO  [org.jboss.ws.common.management] (MSC service thread 1-6) JBWS022052: Starting JBoss Web Services - Stack CXF Server 4.2.1.Final
16:04:22,122 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-8) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
16:04:22,122 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-4) JBAS010400: Bound data source [java:/rapiddb]
16:04:22,247 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9990/management
16:04:22,247 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990
16:04:22,247 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015874: WildFly 8.0.0.Beta2-SNAPSHOT "WildFly" started in 2828ms - Started 186 of 223 services (62 services are lazy, passive or on-demand)

2 个答案:

答案 0 :(得分:2)

我认为这将与您在服务器上的数据源中配置JDBC驱动程序的方式有关,或者如果您在程序包中提供与您使用的实际驱动程序发生冲突的其他驱动程序。

可以在https://community.jboss.org/message/250795

找到类似的错误

如果不能解决问题,请发布您遇到问题的服务器版本。只是为了确保您没有遭受服务器上的固定数据源补丁。

答案 1 :(得分:1)

我在WildFly论坛(WildFly Thread)上发布了这个问题,发现还有另一个包含javax.sql.DataSource接口的jar。

我使用名为jarscan.jar的实用程序来搜索模块中的接口,发现jar包含另一个javax.sql.DataSource类。删除jar表单模块解决了这个问题。