Spring Boot 2.2.6部署至WildFly 20时报WFLYEE0048错误如何解决?
Spring Boot部署WildFly报错WFLYEE0048解决方案
错误根因
该报错是WildFly 20.0.1版本在部署应用时,误将Spring Webflux中的ServletServerHttpRequest.RequestAsyncListener内部类识别为EE组件尝试加载,而该类没有无参默认构造函数,因此抛出WFLYEE0048: Could not find default constructor异常。一般由近期升级Spring Boot版本、项目意外引入Spring Webflux依赖触发。
可用解决方案
- 方案1:排除多余的Spring Webflux依赖
如果你的项目是基于Servlet的传统Spring Web架构,不需要使用Webflux能力,直接全局排除spring-webflux依赖即可解决。
Maven配置参考:
<!-- 针对spring-boot-starter-web排除webflux依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </exclusion> </exclusions> </dependency> <!-- 全局排除spring-webflux依赖,适配间接引入的场景 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webflux</artifactId> <exclusions> <exclusion> <groupId>*</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency>
Gradle配置参考:
configurations { implementation { exclude group: 'org.springframework.boot', module: 'spring-boot-starter-webflux' exclude group: 'org.springframework', module: 'spring-webflux' } }
- 方案2:添加WildFly部署过滤规则
如果项目确实需要使用Webflux相关功能,在项目WEB-INF目录下新增jboss-deployment-structure.xml文件,关闭EE注入扫描即可:
<?xml version="1.0" encoding="UTF-8"?> <jboss-deployment-structure> <deployment> <ee-injection-enabled>false</ee-injection-enabled> <annotation-property-replacement>false</annotation-property-replacement> </deployment> </jboss-deployment-structure>
- 方案3:升级WildFly版本
你当前使用的WildFly 20.0.1为2020年发布的旧版本,升级到WildFly 26及以上版本,官方已经修复了该类加载误判问题,无需修改项目代码即可正常部署。
内容的提问来源于stack exchange,提问作者Ravi MCA
相关产品推荐
相关产品推荐

