You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署Spring Boot Web服务到JBoss EAP 8时遇vfs协议未启用错误

问题描述

基于Spring Boot 3.3.5开发Web服务,采用Log4j2作为日志库。通过Spring Initializer生成项目后,从web模块排除spring-boot-starter-logging以移除Logback,添加了以下Log4j2相关依赖:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-spring-boot</artifactId>
</dependency>
<dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.3.4</version>
</dependency>

同时配置了日志属性、log4j2-spring.xml文件,编写了含日志输出的Controller方法,并通过jboss-deployment-structure.xml排除了相关子系统与模块。部署到JBoss EAP 8时出现错误:

{"WFLYDC0074: Operation failed or was rolled back on all servers. Server failures:" => {"server-group" => {"ProvAccess" => {"host" => {"BCDEVINTRAJB099-primary" => {"ProvAccs1_1" => {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"logtest.war\".undertow-deployment" => "java.lang.RuntimeException: java.lang.IllegalStateException: java.lang.IllegalStateException: Could not initialize Log4J2 logging from classpath:log4j2-spring.xml
    Caused by: java.lang.RuntimeException: java.lang.IllegalStateException: java.lang.IllegalStateException: Could not initialize Log4J2 logging from classpath:log4j2-spring.xml
    Caused by: java.lang.IllegalStateException: java.lang.IllegalStateException: Could not initialize Log4J2 logging from classpath:log4j2-spring.xml
    Caused by: java.lang.IllegalStateException: Could not initialize Log4J2 logging from classpath:log4j2-spring.xml
    Caused by: java.net.ProtocolException: Protocol vfs has not been enabled as an allowed protocol"}}}}}}}}
解决方案

错误核心是Log4j2默认未允许VFS协议(JBoss使用VFS处理类路径资源),需通过以下步骤解决:

1. 配置Log4j2允许VFS协议

在log4j2-spring.xml的根Configuration节点添加allowedProtocols属性,纳入vfs协议:

<Configuration status="INFO" allowedProtocols="vfs,file,http,https">
    <!-- 原有日志配置内容 -->
</Configuration>

如果使用属性文件配置,在application.properties中添加:

logging.log4j.allowed-protocols=vfs,file,http,https

2. 优化依赖配置

  • 移除log4j-spring-boot依赖:spring-boot-starter-log4j2已包含该依赖,重复引入可能引发版本冲突
  • 移除commons-logging依赖:Spring Boot 3.x默认使用spring-jcl替代commons-logging,无需额外引入

优化后的依赖如下:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>

3. 完善jboss-deployment-structure.xml配置

确保完全排除JBoss自带的日志模块,避免类加载冲突:

<jboss-deployment-structure>
    <deployment>
        <exclusions>
            <module name="org.apache.log4j" />
            <module name="org.slf4j" />
            <module name="org.slf4j.impl" />
            <module name="org.jboss.logging" />
            <module name="org.jboss.logging.jul-to-slf4j-stub" />
            <module name="org.jboss.logmanager" />
            <module name="org.jboss.logmanager.log4j" />
        </exclusions>
        <exclude-subsystems>
            <subsystem name="logging" />
        </exclude-subsystems>
    </deployment>
</jboss-deployment-structure>

4. 验证配置文件路径

确认log4j2-spring.xml放置在src/main/resources目录下,打包后位于WAR包的WEB-INF/classes路径中,保证Log4j2能正确读取配置。

内容的提问来源于stack exchange,提问作者Munny

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 05:57:38