LoggerFactory 不是 Logback LoggerContext,但 Logback 位于类路径上。在 Wildfly 上部署 Spring-Boot 应用程序

问题描述 投票:0回答:2

我正在尝试使用 .war 在 Wildfly 服务器上部署 Spring-Boot Vaadin java 应用程序。 不幸的是,我总是收到此错误消息:

2022-04-28 00:23:18,113 ERROR [org.jboss.as.controller.management-operation](DeploymentScanner-threads - 2) WFLYCTL0013: Operation ("full-replace-deployment") failed - address: ([]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"planyoureplaylist-1.0-SNAPSHOT.war\".undertow-deployment" => "java.lang.RuntimeException: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.Slf4jLoggerFactory loaded from jar:file:/C:/ude/Wildfly/wildfly-26.1.0.Final/wildfly-26.1.0.Final/modules/system/layers/base/org/slf4j/impl/main/slf4j-jboss-logmanager-1.1.0.Final.jar!/). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.Slf4jLoggerFactory
Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.Slf4jLoggerFactory loaded from jar:file:/C:/ude/Wildfly/wildfly-26.1.0.Final/wildfly-26.1.0.Final/modules/system/layers/base/org/slf4j/impl/main/slf4j-jboss-logmanager-1.1.0.Final.jar!/). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.Slf4jLoggerFactory
Caused by: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.Slf4jLoggerFactory loaded from jar:file:/C:/ude/Wildfly/wildfly-26.1.0.Final/wildfly-26.1.0.Final/modules/system/layers/base/org/slf4j/impl/main/slf4j-jboss-logmanager-1.1.0.Final.jar!/). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.Slf4jLoggerFactory"}}
2022-04-28 00:23:18,181 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2)WFLYSRV0016: Replaced deployment "planyoureplaylist-1.0-SNAPSHOT.war" with deployment "planyoureplaylist-1.0-SNAPSHOT.war"
2022-04-28 00:23:18,182 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) WFLYCTL0183: Service status report
WFLYCTL0186:   Services which failed to start:      service  jboss.deployment.unit."planyoureplaylist-1.0-SNAPSHOT.war".undertow-deployment:  java.lang.RuntimeException: java.lang.IllegalArgumentException: LoggerFactory is not a  Logback LoggerContext but Logback is on the classpath. Either remove Logback or the  competing implementation (class org.slf4j.impl.Slf4jLoggerFactory loaded from jar:file:/C:/ude/Wildfly/wildfly-26.1.0.Final/wildfly-26.1.0.Final/modules/system/layers/base/org/slf4j /impl/main/slf4j-jboss-logmanager-1.1.0.Final.jar!/). If you are using WebLogic you will  need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml:      org.slf4j.impl.Slf4jLoggerFactory`

我的 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- Vaadin project from https://start.vaadin.com/project/1a8943e6-3b51-4088-a8f4-4c3a070f7245 -->
<groupId>com.planyoureplaylist.application</groupId>
<artifactId>planyoureplaylist</artifactId>
<name>Project base for Spring Boot and Vaadin Flow</name>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<properties>
    <java.version>11</java.version>
    <vaadin.version>14.7.5</vaadin.version>
</properties>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.6.1</version>
</parent>

<repositories>
    <!-- The order of definitions matters. Explicitly defining central here to make sure it has the highest priority. -->

    <!-- Main Maven repository -->
    <repository>
        <id>central</id>
        <url>https://repo.maven.apache.org/maven2</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
    <!-- Repository used by many Vaadin add-ons -->
    <repository>
        <id>Vaadin Directory</id>
        <url>https://maven.vaadin.com/vaadin-addons</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>vaadin-addons</id>
        <url>https://maven.vaadin.com/vaadin-addons</url>
    </repository>
</repositories>

<pluginRepositories>
    <!-- Main Maven repository -->
    <pluginRepository>
        <id>central</id>
        <url>https://repo.maven.apache.org/maven2</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.27</version>
        </dependency>

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

<dependencies>
    <dependency>
        <groupId>com.vaadin</groupId>
        <!-- Replace artifactId with vaadin-core to use only free components -->
        <artifactId>vaadin</artifactId>
        <exclusions>
            <!-- Webjars are only needed when running in Vaadin 13 compatibility mode -->
            <exclusion>
                <groupId>com.vaadin.webjar</groupId>
                <artifactId>*</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.webjars.bowergithub.insites</groupId>
                <artifactId>*</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.webjars.bowergithub.polymer</groupId>
                <artifactId>*</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.webjars.bowergithub.polymerelements</groupId>
                <artifactId>*</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.webjars.bowergithub.vaadin</groupId>
                <artifactId>*</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.webjars.bowergithub.webcomponents</groupId>
                <artifactId>*</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-spring-boot-starter</artifactId>
        <exclusions>
            <!-- Excluding so that webjars are not included. -->
            <exclusion>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-core</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.vaadin.artur</groupId>
        <artifactId>a-vaadin-helper</artifactId>
        <version>1.7.1</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.wildfly.plugins/wildfly-maven-plugin -->
    <dependency>
        <groupId>org.wildfly.plugins</groupId>
        <artifactId>wildfly-maven-plugin</artifactId>
        <version>3.0.0.Final</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-validation</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-testbench</artifactId>
        <scope>test</scope>
    </dependency>
    <!-- Include JUnit 4 support for TestBench and others -->
    <dependency>
        <groupId>org.junit.vintage</groupId>
        <artifactId>junit-vintage-engine</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.hamcrest</groupId>
                <artifactId>hamcrest-core</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>5.0.3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <version>2.6.2</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jdbc -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jdbc</artifactId>
        <version>2.6.2</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
    </dependency>
    <dependency>
        <groupId>se.michaelthelin.spotify</groupId>
        <artifactId>spotify-web-api-java</artifactId>
        <version>7.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.github.fracpete</groupId>
        <artifactId>jclipboardhelper</artifactId>
        <version>0.1.2</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa -->
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>2.6.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>2.6.2</version>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
            <exclusion>
                <artifactId>tomcat-embed-el</artifactId>
                <groupId>org.apache.tomcat.embed</groupId>
            </exclusion>
            <exclusion>
                <artifactId>tomcat-embed-core</artifactId>
                <groupId>org.apache.tomcat.embed</groupId>
            </exclusion>
            <exclusion>
                <artifactId>tomcat-embed-websocket</artifactId>
                <groupId>org.apache.tomcat.embed</groupId>
            </exclusion>
            <exclusion>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-to-slf4j</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-log4j2</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-integration -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-integration</artifactId>
        <version>2.6.7</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-clean-plugin -->
    <dependency>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-clean-plugin</artifactId>
        <version>3.1.0</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>4.0.1</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

<build>
    <defaultGoal>spring-boot:run</defaultGoal>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>2.6.2</version>
            <!-- Clean build and startup time for Vaadin apps sometimes may exceed
                 the default Spring Boot's 30sec timeout.  -->
            <configuration>
                <wait>500</wait>
                <maxAttempts>240</maxAttempts>
            </configuration>
        </plugin>

        <!--
            Take care of synchronizing java dependencies and imports in
            package.json and main.js files.
            It also creates webpack.config.js if not exists yet.
        -->
        <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>

<profiles>
    <profile>
        <!-- Production mode is activated using -Pproduction -->
        <id>production</id>
        <properties>
            <vaadin.productionMode>true</vaadin.productionMode>
        </properties>
        <build>
            <plugins>
                <plugin>
                    <groupId>com.vaadin</groupId>
                    <artifactId>vaadin-maven-plugin</artifactId>
                    <version>${vaadin.version}</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>build-frontend</goal>
                            </goals>
                            <phase>compile</phase>
                        </execution>
                    </executions>
                    <configuration>
                        <productionMode>true</productionMode>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>

    <profile>
        <id>it</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>start-spring-boot</id>
                            <phase>pre-integration-test</phase>
                            <goals>
                                <goal>start</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>stop-spring-boot</id>
                            <phase>post-integration-test</phase>
                            <goals>
                                <goal>stop</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

                <!-- Runs the integration tests (*IT) after the server is started -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>2.22.2</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>integration-test</goal>
                                <goal>verify</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <trimStackTrace>false</trimStackTrace>
                        <enableAssertions>true</enableAssertions>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>3.1.0</version>
                    <configuration>
                        <filesets>
                            <fileset>
                                <directory>.</directory>
                                <includes>
                                    <include>package.json</include>
                                    <include>package-lock.json</include>
                                    <include>webpack.config.js</include>
                                    <include>webpack.generated.js</include>
                                </includes>
                                <followSymlinks>false</followSymlinks>
                            </fileset>
                            <fileset>
                                <directory>./node_modules</directory>
                                <includes>
                                    <include>**/**</include>
                                </includes>
                                <followSymlinks>false</followSymlinks>
                            </fileset>
                        </filesets>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>

</profiles>

我已经尝试使用 logfj 排除任何 Maven 依赖项。 但没有任何帮助...

我也不确定我的问题是否是由于类中存在的记录器语句造成的。 一个例子是:

log.info("从 UserPLaylist 中删除的歌曲。");

抱歉我的英语不好。 :)

感谢您的帮助。

spring-boot deployment log4j wildfly
2个回答
1
投票

经过长时间的搜索,我终于解决了这个问题。 该问题是由两个原因引起的。

1: 对于我的记录器功能,我使用了一个未由 Wildfly 集成的库。 因此我决定使用Wildfly的记录器。 Maven 依赖:

<!-- https://mvnrepository.com/artifact/org.jboss.logging/jboss-logging -->
    <dependency>
        <groupId>org.jboss.logging</groupId>
        <artifactId>jboss-logging</artifactId>
        <version>3.5.0.Final</version>
        <scope>provided</scope>
    </dependency>

我的记录器方法现在看起来像这样:

 private static final Logger log =Logger.getLogger(PlaylistService.class);
 log.info("Get UserPlaylist form Database.");

2: 由于 Vaadin 已经存在相互依赖性,因此存在误解 Wildfly 应该使用哪个记录器库。 根据声明:

mvn dependency:tree

我可以删除重复的和不需要的库(在本例中是 io.github.bonigarcia 中的 slf4j)。 因此,请再次查看应用程序中的 Maven 树,并在 pom.xml 中使用“排除”删除重复的依赖项。

感谢所有提供帮助的人。


0
投票

因为Spring Boot的日志框架和Wildfly的有冲突。

通常您只需将其从 spring-boot-starter-web 依赖项中排除即可:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <artifactId>logback-classic</artifactId>
            <groupId>ch.qos.logback</groupId>
        </exclusion>
    </exclusions>
</dependency>

或者如果您喜欢使用

logback
而不是 Wildfly 的日志系统,您可以在 src/main/webapp/WEB-INF/ 目录下添加
jboss-deployment-struct.xml
。它基本上告诉 Wildfly 不要在您的部署中使用他们的日志系统:

<?xml version="1.0"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <deployment>
    <exclude-subsystems>
      <subsystem name="logging" />
    </exclude-subsystems>
  </deployment>
</jboss-deployment-structure>

请参阅 Wildfly 管理指南

© www.soinside.com 2019 - 2024. All rights reserved.