Spring Boot 2.4.2 - Apple M1 上启动时的 DNS 解析问题

Bar*_*urk 37 java dns spring-boot

我正在将 Spring Boot 版本从 升级2.1.x2.4.2. 当我编译并运行代码时,我收到以下警告:

Unable to load io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider,fallback to system defaults. This may result in incorrect DNS resolutions on MacOS.
java.lang.ClassNotFoundException: io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider
Run Code Online (Sandbox Code Playgroud)

当我将项目部署到AWS和CentOS计算机中的DEV环境时,日志中没有此类警告消息。

谢谢,

Cur*_*lop 25

除了分类器之外,我还需要一个版本:

    <dependency>
        <groupId>io.netty</groupId>
        <artifactId>netty-resolver-dns-native-macos</artifactId>
        <scope>runtime</scope>
        <classifier>osx-x86_64</classifier>
        <version>4.1.59.Final</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

范围是可选的,但分类器是必需的。

最新版本请参见: https://mvnrepository.com/artifact/io.netty/netty-resolver-dns-native-macos

示例:截至 2022 年 1 月,M1 mac 的最新版本 (aarch_64):

<classifier>osx-aarch_64</classifier>
<version>4.1.72.Final</version>
Run Code Online (Sandbox Code Playgroud)

  • @myverdict 如上例所示,M1 芯片使用“osx-aarch_64”。 (2认同)
  • 我并不是说你错了,但我们需要添加依赖项来解决某些问题似乎并不正确。 (2认同)

Pet*_*Cui 14

Gradle 语法(如果您愿意):

compile "io.netty:netty-resolver-dns-native-macos:4.1.72.Final:osx-x86_64"
Run Code Online (Sandbox Code Playgroud)

对于基于 ARM 的 MacBook:

compile "io.netty:netty-resolver-dns-native-macos:4.1.72.Final:osx-aarch_64"
Run Code Online (Sandbox Code Playgroud)


小智 13

对于此拉取请求https://github.com/netty/netty/pull/10848,日志级别从“调试”更改为“警告”。

为了解决这个问题,你可以添加这个依赖:

<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-all</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)


pix*_*xel 6

如果您有 Gradle 并且只想在本地包含 netty,您可以使用https://github.com/google/osdetector-gradle-plugin

plugins {
    id("com.google.osdetector") version "1.7.0"
}

dependencies {
    if (osdetector.arch.equals("aarch_64")) {
        implementation("io.netty:netty-all")
    }
}
Run Code Online (Sandbox Code Playgroud)


Sai*_*pta 5

正如本期所讨论的,它主要发生在使用 Apple Silicon 在 macOS 上进行本地开发期间。

如果您使用 Maven,则在project标签下添加以下内容pom.xml应该可以解决问题:

<profiles>
  <profile>
    <id>macos-m1</id>
    <activation>
      <os>
        <family>mac</family>
        <arch>aarch64</arch>
      </os>
    </activation>
    <dependencies>
      <dependency>
        <groupId>io.netty</groupId>
        <artifactId>netty-resolver-dns-native-macos</artifactId>
        <classifier>osx-aarch_64</classifier>
      </dependency>
    </dependencies>
  </profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)

这可确保配置文件仅针对具有 ARM64 的 macOS 激活。