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

jwensh@2023.12.26

错误

  • 使用 springboot2.7.18 上使用 spring-boot-starter-webflux 的 WebClient 上使用 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")

参考

相关推荐
Raspberry_Pi_官方账号5 小时前
Raspberry Pi Desktop 全面升级,现已登陆 PC 和 Mac
服务器·网络·macos·树莓派·raspberry pi·raspberrypios
大侠归来6 小时前
Spring Boot 2.1 → 3.5 迁移推演:从实战出发的完整路线图
java·spring boot·后端
king13598745506 小时前
EmbeddingGemma 2 270M 实测:Mac CPU、PDF/Word、256d 与 FTS5
macos·pdf·word
Sweet锦6 小时前
jDCS 开源项目:面向工业现场的 Modbus RTU 数据采集基础框架
java·spring boot·物联网·开源
海马6 小时前
Spring Boot 开发知识整理
java·spring boot·后端
谢亮_vipxieliang6 小时前
Spring Boot 3.x 从零开始——环境搭建与第一个 REST 项目
java·spring boot·后端
FYKJ_20106 小时前
django个性化新闻推荐35173-计算机课程设计、毕业设计
java·spring boot·后端·python·架构·django·课程设计
今年下半年6 小时前
【消息队列】Spring Boot 集成 Kafka 消息队列:确保消费完成(手动提交偏移量+幂等判断+失败重试机制)
spring boot·kafka·幂等·失败重试
计算机毕设定制辅导-无忧学长7 小时前
《校园食堂在线订餐小程序的设计与实现》
java·vue.js·spring boot·微信小程序·uniapp·校园食堂在线订餐小程序
IT研究室7 小时前
最新计算机毕业设计选题推荐-基于spring boot的食品安全信息管理系统-网站-文档指导-Java-springboot
java·spring boot·课程设计