Search code examples
javapostgresqljbosswildfly

Jboss Operation("add") failed


I am new in Jboss. I am trying to start Spring Boot with Jboss and encountered a problem with postgres driver. when I start server the following error pops up and crashes .

  > 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"
        ],
    
    

and there is my standelone file

    <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>

and I am using this dependency for 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>

help me please. have you ever had this issue happen to you?.


Solution

  • The problem that the server could not find the driver jar for "postgresql" in your classpath.

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

    Actually, the Datasource subsystem in Jboss by default fetch the driver class in the application classpath, which is loaded by the module name in the driver section. In Jboss you can load modules in 2 ways:

    First: With the app Deployment lib

    Add the Postgres driver jar to your application deployment resource if you are using a deploymen-scanner (JBOSS_APP/<Deployment_directory>/<deployment_filename>.<compress_extension>) with this structure :

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

    Second: External module

    Create a new module in your jboss instance that match the module name in your case it should something like this :

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

    where the module.xml describes this new module resources (the driver jar file), example:

    <?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>
    

    and finally, you need to add the module to the jboss-deployment-structure.xml (app-deployment/WEB-INF/jboss-deployment-structure.xml) to be considred as an external dependncy while deploying the app, example :

    <?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>
    

    This solution is used when the drivers should be managed externally.