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

Spring新手遇JBoss EAP 7部署Jackson绑定错误,WildFly 10正常

Fixing Jackson Databinding Error When Deploying Spring WAR to JBoss EAP 7 (Works on WildFly 10)

Hey there! Let's break down why you're hitting this Jackson databinding issue on JBoss EAP 7—especially since the same WAR deploys smoothly on WildFly 10. The core problem usually boils down to classloader conflicts between JBoss EAP 7's bundled JSON providers (like MOXy) and your Spring app's Jackson dependencies. Here are actionable fixes to resolve this:

1. Exclude JBoss's Built-in MOXy & Jackson Modules

JBoss EAP 7 ships with MOXy as the default JAX-RS JSON provider, and it also includes its own versions of Jackson libraries. These can clash with the Jackson versions your Spring app relies on. To fix this, create a jboss-deployment-structure.xml file in your WAR's WEB-INF directory with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
        <!-- Exclude the JAX-RS subsystem to avoid MOXy interference -->
        <exclude-subsystems>
            <subsystem name="jaxrs"/>
        </exclude-subsystems>
        <!-- Exclude JBoss's bundled Jackson and MOXy modules -->
        <exclusions>
            <module name="com.fasterxml.jackson.core.jackson-databind"/>
            <module name="com.fasterxml.jackson.core.jackson-core"/>
            <module name="com.fasterxml.jackson.core.jackson-annotations"/>
            <module name="org.eclipse.persistence.moxy"/>
        </exclusions>
        <!-- Ensure your app's libraries are loaded before server-wide modules -->
        <local-last value="true"/>
    </deployment>
</jboss-deployment-structure>

This tells JBoss to ignore its own JSON-related modules and prioritize the ones packaged in your WAR.

2. Force Spring to Use Jackson as the Primary JSON Processor

Even after excluding JBoss's modules, you should explicitly configure Spring to use Jackson to avoid any fallback to MOXy. You can do this in two ways:

Option A: Using application.properties (or application.yml)

Add these lines to your Spring config file:

# Set Jackson as the preferred JSON mapper
spring.mvc.converters.preferred-json-mapper=jackson
# Optional: Adjust Jackson serialization settings as needed
spring.jackson.serialization.write-dates-as-timestamps=false
spring.jackson.deserialization.fail-on-unknown-properties=false

Option B: Using Java Configuration

Create a web config class to register Jackson's message converter and remove any MOXy-related converters:

import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        // Add Jackson's converter first
        converters.add(new MappingJackson2HttpMessageConverter());
        // Remove MOXy's XML/JSON converter if present
        converters.removeIf(converter -> converter instanceof Jaxb2RootElementHttpMessageConverter);
    }
}

3. Verify Your WAR's Dependency Tree

Make sure there are no conflicting Jackson versions in your project. Run this command in your project root (if using Maven) to check dependencies:

mvn dependency:tree

Look for any com.fasterxml.jackson entries that have unexpected versions or are marked as provided—you want your app's Jackson dependencies to be set to compile so they're packaged in the WAR.

Why This Works on WildFly 10 but Not JBoss EAP 7

WildFly 10 has a more flexible default configuration for JSON providers, often prioritizing Jackson over MOXy in many cases. JBoss EAP 7, however, is more strict about using its bundled MOXy implementation for JAX-RS, leading to the classloader conflict you're seeing. Adding MOXy manually didn't fix it because the conflict was between JBoss's MOXy/Jackson and your app's Jackson libraries, not a missing dependency.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 08:58:01