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

Spring应用部署环境出现BeanCreationException问题求助

部署环境下Spring应用BeanCreationException排查请求

问题概述

本地运行正常的Spring应用,在部署环境(采用Corretto 11运行Jar包)启动时触发BeanCreationException错误。初步推测问题可能出在Maven依赖层面。该应用通过ApiClientManager类,基于Spring WebFlux的WebClient实现外部API的异步调用,且自定义WebClient已禁用SSL验证。

相关代码

ApiClientManager类核心代码

@Component
public class ApiClientManager {
    private final WebClient webClient;

    public ApiClientManager(WebClient.Builder webClientBuilder) {
        // 自定义SSL禁用配置
        SslContext sslContext = SslContextBuilder.forClient()
                .trustManager(InsecureTrustManagerFactory.INSTANCE)
                .build();
        ClientHttpConnector connector = new ReactorClientHttpConnector(
                HttpClient.create().secure(t -> t.sslContext(sslContext))
        );
        this.webClient = webClientBuilder.clientConnector(connector).build();
    }

    // 外部API调用方法
    public Mono<String> callExternalApi(String url) {
        return webClient.get().uri(url).retrieve().bodyToMono(String.class);
    }
}

WebClient配置类(若有)

@Configuration
public class WebClientConfig {
    @Bean
    public WebClient.Builder webClientBuilder() {
        return WebClient.builder();
    }
}

POM依赖核心配置

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>
    <dependency>
        <groupId>io.netty</groupId>
        <artifactId>netty-handler</artifactId>
    </dependency>
    <!-- 其他业务依赖 -->
</dependencies>

完整错误堆栈信息

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'apiClientManager' defined in file [...ApiClientManager.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [...ApiClientManager]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: io/netty/handler/ssl/SslContextBuilder
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1320)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1214)
    ...
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [...ApiClientManager]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: io/netty/handler/ssl/SslContextBuilder
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:223)
    ...
Caused by: java.lang.NoClassDefFoundError: io/netty/handler/ssl/SslContextBuilder
    at [...ApiClientManager.<init>(ApiClientManager.java:25)]
    ...

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 16:52:11