如何使用.war包装在wildfly-swarm中添加服务模块?

时间:2017-06-14 16:47:02

标签: java maven wildfly-swarm

我在pom.xml中添加了jdbc驱动程序:

<dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>sqljdbc4</artifactId>
    <version>4.0</version>
</dependency>

我添加了project-defaults.yml:

swarm:
  datasources:
    data-sources:
      erp-ds:
        driver-name: sqlserver
        connection-url: jdbc:sqlserver://localhost:1433;DatabaseName=COMPARTILHADO
        user-name: teste
        password: teste
    jdbc-drivers:
      sqlserver:
        driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
        xa-datasource-name: com.microsoft.sqlserver.jdbc.SQLServerXADataSource
        driver-module-name: com.microsoft.sqlserver

但我运行应用程序会抛出异常:

2017-06-14 13:09:54,337 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
    ("subsystem" => "datasources"),
    ("data-source" => "erp-ds")
]) - failure description: {
    "WFLYCTL0412: Required services that are not installed:" => ["jboss.jdbc-driver.sqlserver"],
    "WFLYCTL0180: Services with missing/unavailable dependencies" => [
        "jboss.driver-demander.java:jboss/datasources/erp-ds is missing [jboss.jdbc-driver.sqlserver]",
        "org.wildfly.data-source.erp-ds is missing [jboss.jdbc-driver.sqlserver]"
    ]
}

在Wildfly中,我必须在standalone.xml中添加驱动程序,但我不知道在wildfly-swarm中。在开发阶段,我添加了一个带有jdbcDriver的DatasourcesFraction,它很简单,但是当我构建.war并运行uberjar java -jar ??????-swarm.jar时抛出异常。

1 个答案:

答案 0 :(得分:1)

您实际上在project-defaults.yml中提供了太多信息!

swarm:
  datasources:
    data-sources:
      erp-ds:
        driver-name: sqlserver
        connection-url: jdbc:sqlserver://localhost:1433;DatabaseName=COMPARTILHADO
        user-name: teste
        password: teste

应该就是您所需要的一切。

通过添加com.microsoft.sqlserver:sqljdbc4:4.0作为项目依赖项,WF Swarm将自动为您创建JDBC驱动程序配置。

这可能无法解决您遇到的特定问题,因此我将在/ target中查看WF Swarm修改的WAR(没有.original后缀的那个)并查看您的jdbc jar是否在WEB内部-INF / lib中。