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

p4rjhz4m  于 2023-08-04  发布在  Spring
关注(0)|答案(9)|浏览(366)

我正在将Sping Boot 版本从2.1.x升级到2.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

字符串
当我将项目部署到AWS和CentOS机器中的DEV环境时,日志中没有这样的警告消息。
谢谢你,

az31mfrm

az31mfrm1#

我需要一个版本除了分类器:

<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>

字符串
作用域是可选的,但分类器是必需的。
有关最新版本,请参阅:https://mvnrepository.com/artifact/io.netty/netty-resolver-dns-native-macos
示例:M1 macs的最新版本(aarch_64),截至2022-01:

<classifier>osx-aarch_64</classifier>
<version>4.1.72.Final</version>

8yparm6h

8yparm6h2#

*Gradle 语法**如果您喜欢:

compile "io.netty:netty-resolver-dns-native-macos:4.1.72.Final:osx-x86_64"

字符串
对于基于ARM的MacBook:

compile "io.netty:netty-resolver-dns-native-macos:4.1.72.Final:osx-aarch_64"

juzqafwq

juzqafwq3#

对于这个pull请求https://github.com/netty/netty/pull/10848,日志级别从“debug”更改为“warn”。
要解决此问题,您可以添加此依赖项:

<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-all</artifactId>
</dependency>

字符串

6qqygrtg

6qqygrtg4#

按照here的建议,在模块中添加以下依赖项。

<properties>
  <version.netty>4.1.59.Final</version.netty>
</properties>

<dependency>
  <groupId>io.netty</groupId>
  <artifactId>netty-resolver-dns-native-macos</artifactId>
  <version>${version.netty}</version>
  <scope>runtime</scope>
  <classifier>osx-x86_64</classifier>
</dependency>

字符串
如果您仅在macOS上本地运行应用时遇到此问题,则可以添加特定maven配置文件的依赖项,例如。“本地”。

<profiles>
  <profile>
    <id>local</id>
    <dependencies>
      <dependency>
        <groupId>io.netty</groupId>
        <artifactId>netty-resolver-dns-native-macos</artifactId>
        <version>${version.netty}</version>
        <scope>runtime</scope>
        <classifier>osx-x86_64</classifier>
      </dependency>
    </dependencies>
  </profile>
</profiles>


如果在dependencyManagement中导入netty-bom,则可以避免指定version

svdrlsy4

svdrlsy45#

我的MacBook Pro M1 Pro

<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-all</artifactId>
</dependency>

字符串

093gszye

093gszye6#

如果你有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")
    }
}

字符串

qc6wkl3g

qc6wkl3g7#

<dependency>
                <groupId>io.netty</groupId>
                <artifactId>netty-resolver-dns-native-macos</artifactId>
                <version>4.1.72.Final</version>
                <classifier>osx-aarch_64</classifier>
</dependency>

字符串
它对我的M1 Pro很有效

2izufjch

2izufjch8#

如果您使用Intellij和gradle,请尝试File->invalidate caches

implementation("io.netty:netty-all:4.1.75.Final")

字符串

dwthyt8l

dwthyt8l9#

它主要发生在使用Apple Silicon在macOS上进行本地开发期间,如this issue中所讨论的。
如果你使用的是Maven,那么在pom.xml中的project标签下添加以下内容应该可以解决这个问题:

<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>

字符串
这可确保配置文件仅针对安装了ARM64的macOS激活。

相关问题