如何将可以由WebApp使用的JDBC驱动程序部署到Wildfly

时间:2017-06-26 07:56:12

标签: jdbc wildfly wildfly-10

我们目前正在从Tomcat迁移到Wildfly 10服务器。我们喜欢利用Java EE Server。目前我们在DataSource方面存在一些问题。我们在Wildfly上部署了JDBC驱动程序并设置了DataSource。 这主要是好的,但我们喜欢使用DatabaseQueryNotification(Oracle)进行数据库端事件。

现在遇到的问题是:

当我用我的战争(另外)打包驱动程序时,由于T4Connection和OracleConnection不匹配,我得到一个ClassCastException。因此,我从我的战争中移除了JDBC驱动程序(maven - >范围:提供)。但是现在我的应用程序在部署上失败了,因为NoClassDefFound(参见Stacktrace bellow)。

如何确保应用程序可以找到JDBC驱动程序?

Java代码段:

public class DBListener implements IDBListener, Runnable, DatabaseChangeListener, IPropertyListener, Serializable {  
     @Resource(lookup = "java:/PlsDS")  
     private DataSource dataSource;  
     ...  
     public void connectToDB(){
       Connection tmpCon = dataSource.getConnection();  
       connection = (OracleConnection) tmpCon.getMetaData().getConnection();  
       ...
     }
}

堆栈跟踪:

14:32:59,869 WARN  [org.jboss.modules] (MSC service thread 1-7) Failed to define class de.istec.pls.client.db.listener.DBListener in Module "deployment.client.pls-sc-1.0.0-SNAPSHOT.war:main" from Service Module Loader: java.lang.NoClassDefFoundError: Failed to link de/istec/pls/client/db/listener/DBListener (Module "deployment.client.pls-sc-1.0.0-SNAPSHOT.war:main" from Service Module Loader): oracle/jdbc/dcn/DatabaseChangeListener
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:446)
    at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:274)
    at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:78)
    at org.jboss.modules.Module.loadModuleClass(Module.java:606)
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351)
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93)
    at org.wildfly.extension.undertow.deployment.ServletContainerInitializerDeploymentProcessor.loadClassInfoSet(ServletContainerInitializerDeploymentProcessor.java:259)
    at org.wildfly.extension.undertow.deployment.ServletContainerInitializerDeploymentProcessor.deploy(ServletContainerInitializerDeploymentProcessor.java:169)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:147)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

14:32:59,871 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-7) MSC000001: Failed to start service jboss.deployment.unit."client.pls-sc-1.0.0-SNAPSHOT.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."client.pls-sc-1.0.0-SNAPSHOT.war".INSTALL: WFLYSRV0153: Failed to process phase INSTALL of deployment "client.pls-sc-1.0.0-SNAPSHOT.war"
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:154)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

Caused by: java.lang.NoClassDefFoundError: Failed to link de/istec/pls/client/db/listener/DBListener (Module "deployment.client.pls-sc-1.0.0-SNAPSHOT.war:main" from Service Module Loader): oracle/jdbc/dcn/DatabaseChangeListener
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:446)
    at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:274)
    at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:78)
    at org.jboss.modules.Module.loadModuleClass(Module.java:606)
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351)
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93)
    at org.wildfly.extension.undertow.deployment.ServletContainerInitializerDeploymentProcessor.loadClassInfoSet(ServletContainerInitializerDeploymentProcessor.java:259)
    at org.wildfly.extension.undertow.deployment.ServletContainerInitializerDeploymentProcessor.deploy(ServletContainerInitializerDeploymentProcessor.java:169)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:147)

2 个答案:

答案 0 :(得分:1)

我已经解决了问题:

  1. 我必须将JDBC驱动程序部署为模块(请参阅: http://hpehl.info/jdbc-driver-setup.html
  2. 我必须从模块
  3. 导出所需的oracle.jdbc.dcn *文件
  4. 在Manifest.MF文件中插入Dependency。 (可以由Maven完成,见下文)
  5. <强> module.xml

    <module xmlns="urn:jboss:module:1.1" name="com.oracle">
      <resources>
        <resource-root path="ojdbc7-12.1.0.2.jar"/>
      </resources>
      <dependencies>
        <system export="true">
            <paths>
                <path name="oracle/jdbc/OracleStatement"/>
                <path name="oracle/jdbc/dcn/DatabaseChangeEvent"/>
                <path name="oracle/jdbc/dcn/DatabaseChangeListener"/>
                <path name="oracle/jdbc/dcn/DatabaseChangeRegistration"/>
                <path name="oracle/jdbc/dcn/QueryChangeDescription"/>
                <path name="oracle/jdbc/dcn/RowChangeDescription"/>
            </paths>
        </system>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
      </dependencies>
    </module>
    

    <强>的pom.xml

    <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.1.0</version>
        <configuration>
            <archive>
              <manifestEntries>
                 <Dependencies>com.oracle</Dependencies>
              </manifestEntries>
            </archive>
        </configuration>
    </plugin>
    

答案 1 :(得分:-2)

您应该通过JNDI获取数据源的实例或通过CDI注入。