【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")

参考

相关推荐
麦兜*18 分钟前
Spring Boot整合PyTorch Pruning工具链,模型瘦身手术
java·pytorch·spring boot·后端·spring cloud·ai编程·剪枝
杨荧3 小时前
基于大数据的美食视频播放数据可视化系统 Python+Django+Vue.js
大数据·前端·javascript·vue.js·spring boot·后端·python
架构师沉默7 小时前
我用一个 Postgres 实现一整套后端架构!
java·spring boot·程序人生·架构·tdd
xiucai_cs7 小时前
布隆过滤器原理与Spring Boot实战
java·spring boot·后端·布隆过滤器
巴拉巴巴巴拉7 小时前
Spring Boot 中 YAML 配置文件详解
spring boot
向阳花自开7 小时前
Spring Boot 常用注解速查表
java·spring boot·后端
一只爱撸猫的程序猿8 小时前
创建一个使用Spring AI结合MCP(Model Context Protocol)和Dify构建智能客服系统的简单案例
spring boot·aigc·ai编程
归辞...9 小时前
「iOS」————自动释放池底层原理
macos·ios·cocoa
高克莱9 小时前
【macOS操作系统部署开源DeepSeek大模型,搭建Agent平台,构建私有化RAG知识库完整流程】
macos·llm·agent·知识库·anythingllm·ollama·deepseek
꧁༺摩༒西༻꧂9 小时前
Spring Boot Actuator 监控功能的简介及禁用
java·数据库·spring boot