Search code examples
spring-bootwildflywildfly-maven-plugin

wildfly-maven-plugin: Error creating bean with name 'undertowServletWebServerFactory'


Trying to deploy spring boot app to wildfly. This is my pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>pro.profsoft</groupId>
    <artifactId>admin</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>admin</name>
    <description>administration panel</description>

    <properties>
        <java.version>1.8</java.version>
        <vaadin.version>14.2.3</vaadin.version>
        <junit.jupiter.version>5.7.0-M1</junit.jupiter.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <wildfly-hostname>localhost</wildfly-hostname>
        <wildfly-port>9990</wildfly-port>
        <wildfly-username>wildfly</wildfly-username>
        <wildfly-password>wildfly</wildfly-password>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>${junit.jupiter.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.wildfly.plugins/wildfly-maven-plugin -->
        <dependency>
            <groupId>org.wildfly.plugins</groupId>
            <artifactId>wildfly-maven-plugin</artifactId>
            <version>2.0.2.Final</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.reactivestreams/reactive-streams -->
        <dependency>
            <groupId>org.reactivestreams</groupId>
            <artifactId>reactive-streams</artifactId>
            <version>1.0.3</version>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-bom</artifactId>
                <version>${vaadin.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <finalName>${project.name}</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <version>2.0.2.Final</version>
                <configuration>
                    <hostname>${wildfly-hostname}</hostname>
                    <port>${wildfly-port}</port>
                    <username>${wildfly-username}</username>
                    <password>${wildfly-password}</password>
                    <name>${project.name}.war</name>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-maven-plugin</artifactId>
                <version>${vaadin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-frontend</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

When I start mvn wildfly:deploy getting an error.

[ERROR] Failed to execute goal org.wildfly.plugins:wildfly-maven-plugin:2.0.2.Final:deploy (default-cli) on project admin: Failed to execute goal deploy: {"WFLYCTL0062: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-1" => {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit."admin.war".undertow-deployment" => "java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'undertowServletWebServerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryConfiguration$EmbeddedUndertow.class]: Initialization of bean failed; nested exception is java.lang.LinkageError: loader constraint violation: when resolving field "MAX_HEADER_SIZE" the class loader (instance of org/jboss/modules/ModuleClassLoader) of the referring class, io/undertow/UndertowOptions, and the class loader (instance of org/jboss/modules/ModuleClassLoader) for the field's resolved type, org/xnio/Option, have different Class objects for that type [ERROR] Caused by: java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'undertowServletWebServerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryConfiguration$EmbeddedUndertow.class]: Initialization of bean failed; nested exception is java.lang.LinkageError: loader constraint violation: when resolving field "MAX_HEADER_SIZE" the class loader (instance of org/jboss/modules/ModuleClassLoader) of the referring class, io/undertow/UndertowOptions, and the class loader (instance of org/jboss/modules/ModuleClassLoader) for the field's resolved type, org/xnio/Option, have different Class objects for that type [ERROR] Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'undertowServletWebServerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryConfiguration$EmbeddedUndertow.class]: Initialization of bean failed; nested exception is java.lang.LinkageError: loader constraint violation: when resolving field "MAX_HEADER_SIZE" the class loader (instance of org/jboss/modules/ModuleClassLoader) of the referring class, io/undertow/UndertowOptions, and the class loader (instance of org/jboss/modules/ModuleClassLoader) for the field's resolved type, org/xnio/Option, have different Class objects for that type [ERROR] Caused by: java.lang.LinkageError: loader constraint violation: when resolving field "MAX_HEADER_SIZE" the class loader (instance of org/jboss/modules/ModuleClassLoader) of the referring class, io/undertow/UndertowOptions, and the class loader (instance of org/jboss/modules/ModuleClassLoader) for the field's resolved type, org/xnio/Option, have different Class objects for that type"}}}}

As I understand it, the reason is dependencies. How to fix it?


Solution

  • It turned out that there is a conflict with the library pulled by the plugin

    <dependency>
        <groupId>org.wildfly.plugins</groupId>
        <artifactId>wildfly-maven-plugin</artifactId>
        <version>2.0.2.Final</version>
        <exclusions>
            <exclusion>
                <groupId>org.jboss.xnio</groupId>
                <artifactId>xnio-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>