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

参考

相关推荐
一 乐2 小时前
婚纱摄影网站|基于ssm + vue婚纱摄影网站系统(源码+数据库+文档)
前端·javascript·数据库·vue.js·spring boot·后端
期待のcode4 小时前
前后端分离项目 Springboot+vue 在云服务器上的部署
服务器·vue.js·spring boot
ProgramHan5 小时前
Spring Boot 3.2 新特性:虚拟线程的落地实践
java·jvm·spring boot
源码获取_wx:Fegn08956 小时前
基于 vue智慧养老院系统
开发语言·前端·javascript·vue.js·spring boot·后端·课程设计
毕设源码_郑学姐6 小时前
计算机毕业设计springboot基于HTML5的酒店预订管理系统 基于Spring Boot框架的HTML5酒店预订管理平台设计与实现 HTML5与Spring Boot技术驱动的酒店预订管理系统开
spring boot·后端·课程设计
不吃香菜学java6 小时前
spring-依赖注入
java·spring boot·后端·spring·ssm
南部余额6 小时前
Spring Boot 整合 MinIO:封装常用工具类简化文件上传、启动项目初始化桶
java·spring boot·后端·文件上传·工具类·minio·minioutils
QQ19632884756 小时前
ssm基于Springboot+的球鞋销售商城网站vue
vue.js·spring boot·后端
太空眼睛7 小时前
【MCP】使用SpringBoot基于Streamable-HTTP构建MCP-Server
spring boot·sse·curl·mcp·mcp-server·spring-ai·streamable
幽络源小助理7 小时前
springboot校园车辆管理系统源码 – SpringBoot+Vue项目免费下载 | 幽络源
vue.js·spring boot·后端