【问题标题】:Spring Boot 2.4.2 - DNS Resolution Problem at start on Apple M1Spring Boot 2.4.2 - Apple M1 启动时的 DNS 解析问题
【发布时间】:2021-05-03 09:05:20
【问题描述】:

我正在将我的 Spring 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 环境时,日志中没有这样的警告消息。

谢谢,

【问题讨论】:

    标签: java spring-boot dns


    【解决方案1】:

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

        <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 年 1 月:

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

    【讨论】:

      【解决方案2】:

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

      要解决这个问题,可以添加这个依赖:

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

      【讨论】:

        【解决方案3】:

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

        【讨论】:

        • 这似乎不再解决问题
        【解决方案4】:

        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"
        

        【讨论】:

          【解决方案5】:

          这个在我的 MacBook Pro M1 Pro 上工作

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

          【讨论】:

            【解决方案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")
                }
            }
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 2015-01-12
              • 1970-01-01
              • 2022-10-20
              • 1970-01-01
              • 1970-01-01
              • 2021-04-12
              • 2017-02-13
              • 1970-01-01
              相关资源
              最近更新 更多