升级到Micronaut 3.0后Http Client报ClassNotFoundException: AsyncSSLPrivateKeyMethod
问题根因
该报错由Netty版本冲突导致:Micronaut 3.0绑定的Netty 4.1.x版本依赖tcnative原生SSL组件的特定版本,若项目中其他依赖引入了版本不匹配的Netty或tcnative包,就会出现AsyncSSLPrivateKeyMethod类缺失的问题。
解决步骤
第一步:排查依赖版本冲突
先执行命令确认当前项目的Netty版本情况:
- Gradle项目执行:
./gradlew dependencies --configuration runtimeClasspath | grep io.netty - Maven项目执行:
mvn dependency:tree | grep io.netty
检查所有io.netty开头的依赖版本是否统一,重点看netty-tcnative、netty-tcnative-classes的版本是否和Netty核心包版本配套。
第二步:选择对应修复方案
方案1:强制统一Netty版本
在构建配置中锁定和Micronaut 3.0配套的Netty版本即可解决冲突:
Gradle配置示例(添加到build.gradle中):
configurations.all { resolutionStrategy { force 'io.netty:netty-codec-http2:4.1.72.Final' force 'io.netty:netty-handler:4.1.72.Final' force 'io.netty:netty-tcnative:2.0.46.Final' force 'io.netty:netty-tcnative-classes:2.0.46.Final' } }
Maven配置示例(添加到pom.xml的dependencyManagement节点中):
<dependency> <groupId>io.netty</groupId> <artifactId>netty-bom</artifactId> <version>4.1.72.Final</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>io.netty</groupId> <artifactId>netty-tcnative-classes</artifactId> <version>2.0.46.Final</version> </dependency>
方案2:测试场景临时绕开(无需SSL时使用)
如果测试用例不需要调用HTTPS接口,可直接在测试配置文件application-test.yml中禁用客户端SSL,跳过相关类加载:
micronaut: http: client: ssl: enabled: false
方案3:手动补充缺失依赖
若版本锁定后仍报错,直接手动添加缺失的tcnative类依赖:
Gradle:
implementation("io.netty:netty-tcnative-classes:2.0.46.Final")
Maven:
<dependency> <groupId>io.netty</groupId> <artifactId>netty-tcnative-classes</artifactId> <version>2.0.46.Final</version> </dependency>
第三步:验证修复
修改配置后清除构建缓存刷新依赖,重新运行测试:
- Gradle:
./gradlew clean test --refresh-dependencies - Maven:
mvn clean test -U
内容的提问来源于stack exchange,提问作者IEE1394
相关产品推荐
相关产品推荐

