【Springboot】解决 MacOS M1 上 Netty 的 DNS 解析错误

jwensh@2023.12.26

错误

  • 使用 springboot2.7.18 上使用 spring-boot-starter-webfluxWebClient 上使用 netty 的 connector 来进行

  • 引用

java 复制代码
implementation("org.springframework.boot:spring-boot-starter-webflux")
  • 使用
java 复制代码
import reactor.netty.http.client.HttpClient;

···

HttpClient httpClient = HttpClient.create()
                .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000);

WebClient webClient = builder.clone()
                .defaultCookie("cookie-name", "cookie-value")
                .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
                .clientConnector(new ReactorClientHttpConnector(httpClient))
                .build();
  • 错误
text 复制代码
2023-12-26 09:52:20.123 [restartedMain] ERROR i.n.resolver.dns.DnsServerAddressStreamProviders - 
	Unable to load io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider,
	fallback to system defaults. This may result in incorrect DNS resolutions on 
	MacOS. Check whether you have a dependency on 'io.netty:netty-resolver-dns-native-macos'.
	Use DEBUG level to see the full stack: java.lang.UnsatisfiedLinkError: failed to load the required native library 

是使用 Netty 库时遇到的 DNS 解析错误;此错误源于 Netty 无法访问本机 MacOS DNS 解析器。这样做的后果是可能出现不正确的 DNS 解析,这可能会导致应用程序中出现大量与网络相关的问题;

原因

Netty 使用本机代码与系统的 DNS 解析器交互以获得最佳性能。在 MacOS 上,尤其是使用 M1 芯片的系统上,可能会缺少所需的本机库,从而导致上述错误。

解决方案是显式提供此本机库。

解决方案

对于使用 Gradle 管理的项目,您需要在 build.gradle 文件中包含以下依赖项:

java 复制代码
runtimeOnly("io.netty:netty-resolver-dns-native-macos:4.1.76.Final:osx-aarch_64")

参考

相关推荐
goodmao2 小时前
【macOS】【mouse】设置鼠标大小
macos·计算机外设·鼠标·mouse
m0_740043733 小时前
【无标题】
java·spring boot·spring·spring cloud·微服务
重整旗鼓~3 小时前
1.外卖项目介绍
spring boot
Magnum Lehar3 小时前
macos信息采集器appledataharvester-3
macos·网络安全·系统安全
一点技术4 小时前
基于SpringBoot的选课调查系统
java·spring boot·后端·选课调查系统
shuair4 小时前
redis实现布隆过滤器
spring boot·redis·bootstrap
RANCE_atttackkk5 小时前
Springboot+langchain4j的RAG检索增强生成
java·开发语言·spring boot·后端·spring·ai·ai编程
川川菜鸟5 小时前
Claude Code 安装与配置完整指南(Mac)
macos
WarmSword6 小时前
mac上用cursor/vscode调试root权限进程
c++·ide·vscode·macos·mac
好好研究7 小时前
Spring Boot - Thymeleaf模板引擎
java·spring boot·后端·thymeleaf