【问题标题】:Jboss Operation("add") failedJboss 操作(“添加”)失败
【发布时间】:2021-08-10 12:11:06
【问题描述】:

我是 Jboss 的新手。我正在尝试使用 Jboss 启动 Spring Boot,但遇到了 postgres 驱动程序的问题。当我启动服务器时,会弹出以下错误并崩溃。

  > 13:00:47,681 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
        ("subsystem" => "datasources"),
        ("data-source" => "DigitalFarm_DS")
    ]) - failure description: {
        "WFLYCTL0412: Required services that are not installed:" => ["jboss.jdbc-driver.postgresql"],
        "WFLYCTL0180: Services with missing/unavailable dependencies" => [
            "org.wildfly.data-source.DigitalFarm_DS is missing [jboss.jdbc-driver.postgresql]",
            "jboss.driver-demander.java:jboss/datasources/DigitalFarmDS is missing [jboss.jdbc-driver.postgresql]"
        ]
    }
    13:00:47,682 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
        ("subsystem" => "datasources"),
        ("data-source" => "DigitalFarm_DS")
    ]) - failure description: {
        "WFLYCTL0412: Required services that are not installed:" => [
            "jboss.jdbc-driver.postgresql",
            "jboss.jdbc-driver.postgresql"
        ],
    
    

还有我的独立文件

    <datasources>
                <datasource jndi-name="java:jboss/datasources/DigitalFarmDS" pool-name="DigitalFarm_DS" enabled="true" use-java-context="true" statistics-enabled="true">
                    <connection-url>jdbc:postgresql://localhost:5432/DigitalFarm</connection-url>
                    <driver>postgresql</driver>
                    <security>
                        <user-name>_db_username</user-name>
                        <password>_db_password_</password>
                    </security>
                </datasource>
                <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true" statistics-enabled="${wildfly.datasources.statistics-enabled:${wildfly.statistics-enabled:false}}">
                    <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
                    <driver>h2</driver>
                    <security>
                        <user-name>sa</user-name>
                        <password>sa</password>
                    </security>
                </datasource>
                <drivers>
                    <driver name="postgresql" module="org.postgresql">
                        <driver-class>org.postgresql.Driver</driver-class>
                        <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
                    </driver>
                    <driver name="h2" module="com.h2database.h2">
                        <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                    </driver>
                </drivers>
            </datasources>

我正在为 wildfly 使用此依赖项

    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.tomcat.embed</groupId>
                    <artifactId>tomcat-embed-websocket</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

请帮帮我。你有遇到过这个问题吗?

【问题讨论】:

    标签: java postgresql jboss wildfly


    【解决方案1】:

    服务器在你的类路径中找不到“postgresql”的驱动jar的问题。

            "WFLYCTL0180: Services with missing/unavailable dependencies" => [
            "org.wildfly.data-source.DigitalFarm_DS is missing [jboss.jdbc-driver.postgresql]"
    

    实际上,Jboss 中的 Datasource 子系统默认获取应用程序类路径中的驱动程序类,该驱动程序类是通过驱动程序部分中的模块名称加载的。 在 Jboss 中,您可以通过 2 种方式加载模块:

    首先:使用应用部署库

    如果您使用具有此结构的部署扫描器 (JBOSS_APP//.),请将 Postgres 驱动程序 jar 添加到应用程序部署资源:

    app-deployment.war
     |_WEB-INF
      |_lib
       |_postgresql-42.2.5.jar (example version)
    

    二:外部模块

    在您的 jboss 实例中创建一个与您的模块名称匹配的新模块,它应该是这样的:

    modules
    |_org
     |_postgresql
      |_main
       |_postgresql-42.2.5.jar
       |_module.xml
    

    module.xml 描述这个新的模块资源(驱动 jar 文件)的地方,例如:

    <?xml version="1.0" encoding="UTF-8"?>
    <module xmlns="urn:jboss:module:1.7" name="org.postgresql">
    
        <resources>
            <resource-root path="postgresql-42.2.5.jar.jar"/>
        </resources>
    
        <dependencies>
            <module name=""/>
          ...
        </dependencies>
    
    </module>
    

    最后,您需要将模块添加到 jboss-deployment-structure.xml (app-deployment/WEB-INF/jboss-deployment-structure.xml) 以在部署应用程序时被视为外部依赖项,示例:

    <?xml version='1.0' encoding='UTF-8'?>
    <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
        <deployment>
             <dependencies>
                ...
                 <module name="org.postgresql"/>
                ...
            </dependencies>
    
        </deployment>         
        
    </jboss-deployment-structure>
    

    当需要从外部管理驱动程序时使用此解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 2012-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多