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

如何解决Wildfly Swarm中SwaggerSerializers类的WELD-001318错误?

Fixing Ambiguous SwaggerSerializers Dependency in Wildfly Swarm 2017.12.1

I’ve dealt with this exact frustrating issue before—those ambiguous CDI resolution errors from duplicate Swagger classes are a real headache. Since you want to avoid manually listing all fractions just to exclude Swagger, here are three practical, clean fixes:

1. Exclude the Swagger Fraction Without Disabling Auto-Discovery

You can keep relying on Wildfly Swarm’s automatic fraction detection while specifically skipping the unstable Swagger fraction. There are two straightforward ways to do this in your pom.xml:

Option A: Exclude via Core Dependency

Add an exclusion to your base Wildfly Swarm dependency:

<dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>wildfly-swarm</artifactId>
    <version>2017.12.1</version>
    <type>pom</type>
    <exclusions>
        <exclusion>
            <groupId>org.wildfly.swarm</groupId>
            <artifactId>swagger</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Option B: Exclude via Maven Plugin

If you’re using the Wildfly Swarm Maven plugin, add an exclusion directly to its configuration:

<plugin>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>wildfly-swarm-plugin</artifactId>
    <version>2017.12.1</version>
    <configuration>
        <excludedFractions>
            <excludedFraction>swagger</excludedFraction>
        </excludedFractions>
    </configuration>
</plugin>

Both approaches let Swarm continue auto-discovering all other required fractions while ditching the problematic Swagger one.

2. Upgrade to a Fixed Wildfly Swarm Version

The SWARM-271 bug you referenced was resolved in later releases. Upgrading to 2018.1.1 or any subsequent version will eliminate the duplicate Swagger class issue entirely. Just update the version number across all your Wildfly Swarm dependencies and plugins:

<properties>
    <wildfly-swarm.version>2018.1.1</wildfly-swarm.version>
</properties>

This is the cleanest long-term solution, as it also gets you other bug fixes and minor improvements.

3. Temporary CDI Ambiguity Workaround (Last Resort)

If you can’t exclude or upgrade right now, you can force CDI to resolve the ambiguity by prioritizing one instance of SwaggerSerializers. Create a producer method in your code:

import javax.enterprise.inject.Produces;
import javax.annotation.Priority;
import javax.interceptor.Interceptor;
import io.swagger.jaxrs.listing.SwaggerSerializers;

public class SwaggerSerializerProducer {
    @Produces
    @Priority(Interceptor.Priority.APPLICATION + 1)
    public SwaggerSerializers produceSwaggerSerializers() {
        return new SwaggerSerializers();
    }
}

This tells CDI to use your produced instance over the duplicate ones. Note: This is a hacky workaround and should only be used if the first two options aren’t feasible.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 07:08:12