[英]Spring Api-Gateway: (M1) java.lang.UnsatisfiedLinkError: no netty_resolver_dns_native_macos_aarch_64
Just to clearify this only occurs on M1 Mac, the intel version doesn't seem to have this problem.只是为了澄清这只发生在 M1 Mac 上,intel 版本似乎没有这个问题。
JDK 17 JDK 17
openjdk version "17.0.1" 2021-10-19
OpenJDK Runtime Environment Homebrew (build 17.0.1+1)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.1+1, mixed mode, sharing)
# List of all JDK
Matching Java Virtual Machines (2):
17.0.1 (arm64) "Homebrew" - "OpenJDK 17.0.1" /opt/homebrew/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home
16.0.2 (arm64) "Azul Systems, Inc." - "Zulu 16.32.15" /Users/xxxxxx/Library/Java/JavaVirtualMachines/azul-16.0.2/Contents/Home
/opt/homebrew/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home
Project Diagram工程图
Problem:问题:
java.lang.UnsatisfiedLinkError
exception is thrown when trying to access one of the microservice through API-Gateway. java.lang.UnsatisfiedLinkError
尝试通过 API 网关访问其中一个微服务时抛出异常。 For example, http://localhost:8082/API-USER/users/status/ok
will throw this exception.例如
http://localhost:8082/API-USER/users/status/ok
会抛出这个异常。
The return
value is correct, API-Gateway continuse to run dispite the annoying exception. return
值是正确的,API-Gateway 继续运行,尽管有烦人的异常。
Caused by: java.lang.UnsatisfiedLinkError: failed to load the required native library
at io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider.ensureAvailability(MacOSDnsServerAddressStreamProvider.java:110) ~[netty-resolver-dns-classes-macos-4.1.75.Final.jar:4.1.75.Final]
Caused by: java.lang.UnsatisfiedLinkError: failed to load the required native library
at io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider.<init>(MacOSDnsServerAddressStreamProvider.java:120) ~[netty-resolver-dns-classes-macos-4.1.75.Final.jar:4.1.75.Final]
... 202 common frames omitted
Caused by: java.lang.UnsatisfiedLinkError: could not load a native library: netty_resolver_dns_native_macos_aarch_64
at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:224) ~[netty-common-4.1.75.Final.jar:4.1.75.Final]
at io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider.loadNativeLibrary(MacOSDnsServerAddressStreamProvider.java:92) ~[netty-resolver-dns-classes-macos-4.1.75.Final.jar:4.1.75.Final]
at io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider.<clinit>(MacOSDnsServerAddressStreamProvider.java:77) ~[netty-resolver-dns-classes-macos-4.1.75.Final.jar:4.1.75.Final]
at java.base/java.lang.Class.forName0(Native Method) ~[na:na]
Caused by: java.lang.UnsatisfiedLinkError: could not load a native library: netty_resolver_dns_native_macos_aarch_64
at java.base/java.lang.Class.forName(Class.java:467) ~[na:na]
at io.netty.resolver.dns.DnsServerAddressStreamProviders$1.run(DnsServerAddressStreamProviders.java:50) ~[netty-resolver-dns-4.1.75.Final.jar:4.1.75.Final]
at java.base/java.security.AccessController.doPrivileged(AccessController.java:318) ~[na:na]
at io.netty.resolver.dns.DnsServerAddressStreamProviders.<clinit>(DnsServerAddressStreamProviders.java:46) ~[netty-resolver-dns-4.1.75.Final.jar:4.1.75.Final]
... 196 common frames omitted
Suppressed: java.lang.UnsatisfiedLinkError: could not load a native library: netty_resolver_dns_native_macos
at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:224) ~[netty-common-4.1.75.Final.jar:4.1.75.Final]
at io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider.loadNativeLibrary(MacOSDnsServerAddressStreamProvider.java:95) ~[netty-resolver-dns-classes-macos-4.1.75.Final.jar:4.1.75.Final]
... 202 common frames omitted
Caused by: java.io.FileNotFoundException: META-INF/native/libnetty_resolver_dns_native_macos.jnilib
at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:166)
Caused by: java.io.FileNotFoundException: META-INF/native/libnetty_resolver_dns_native_macos.jnilib
... 203 common frames omitted
Suppressed: java.lang.UnsatisfiedLinkError: no netty_resolver_dns_native_macos in java.library.path: /Users/erichuang/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2429)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818)
at java.base/java.lang.System.loadLibrary(System.java:1989)
at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:376)
at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:146)
... 203 common frames omitted
Suppressed: java.lang.UnsatisfiedLinkError: no netty_resolver_dns_native_macos in java.library.path: /Users/erichuang/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2429)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818)
at java.base/java.lang.System.loadLibrary(System.java:1989)
at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at io.netty.util.internal.NativeLibraryLoader$1.run(NativeLibraryLoader.java:410)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
at io.netty.util.internal.NativeLibraryLoader.loadLibraryByHelper(NativeLibraryLoader.java:402)
at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:368)
... 204 common frames omitted
Caused by: java.io.FileNotFoundException: META-INF/native/libnetty_resolver_dns_native_macos_aarch_64.jnilib
at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:166) ~[netty-common-4.1.75.Final.jar:4.1.75.Final]
... 203 common frames omitted
Suppressed: java.lang.UnsatisfiedLinkError: no netty_resolver_dns_native_macos_aarch_64 in java.library.path: /Users/erichuang/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2429) ~[na:na]
Caused by: java.io.FileNotFoundException: META-INF/native/libnetty_resolver_dns_native_macos_aarch_64.jnilib
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818) ~[na:na]
at java.base/java.lang.System.loadLibrary(System.java:1989) ~[na:na]
at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38) ~[netty-common-4.1.75.Final.jar:4.1.75.Final]
at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:376) ~[netty-common-4.1.75.Final.jar:4.1.75.Final]
at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:146) ~[netty-common-4.1.75.Final.jar:4.1.75.Final]
... 203 common frames omitted
Suppressed: java.lang.UnsatisfiedLinkError: no netty_resolver_dns_native_macos_aarch_64 in java.library.path: /Users/erichuang/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2429)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818)
at java.base/java.lang.System.loadLibrary(System.java:1989)
at io.netty.util.internal.NativeLibraryUtil.loadLibrary(NativeLibraryUtil.java:38)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at io.netty.util.internal.NativeLibraryLoader$1.run(NativeLibraryLoader.java:410)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
at io.netty.util.internal.NativeLibraryLoader.loadLibraryByHelper(NativeLibraryLoader.java:402)
at io.netty.util.internal.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:368)
... 204 common frames omitted
Question问题
Does any one know how to mitigate this error?有谁知道如何减轻这个错误?
I tired...我累了...
Both of these links suggested to add netty-tcnative-boringssl-static
dependency but that didn't work as well....这两个链接都建议添加
netty-tcnative-boringssl-static
依赖项,但效果不佳......
API-Gateway: build.gradle
API网关:
build.gradle
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
// https://mvnrepository.com/artifact/io.netty/netty-tcnative-boringssl-static
implementation group: 'io.netty', name: 'netty-tcnative-boringssl-static', version: '2.0.51.Final'
}
Thanks for helping
Found an issue on GitHub: https://github.com/netty/netty/issues/11020在 GitHub 上发现一个问题: https ://github.com/netty/netty/issues/11020
Get the newest version: https://mvnrepository.com/artifact/io.netty/netty-resolver-dns-native-macos获取最新版本: https ://mvnrepository.com/artifact/io.netty/netty-resolver-dns-native-macos
Still doesn't explain why this problem occurs, but here it is that fixed the issue for me:仍然没有解释为什么会出现这个问题,但它为我解决了这个问题:
Maven马文
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-resolver-dns-native-macos</artifactId>
<version>XXX</version>
<classifier>osx-aarch_64</classifier>
</dependency>
Gradle摇篮
implementation group: 'io.netty', name: 'netty-resolver-dns-native-macos', version: 'xxx', classifier: 'osx-aarch_64'
You must add the proper classifier to the to the netty-resolver-dns-native-macos artifact, so that the proper version of the native library is loaded:您必须将正确的分类器添加到 netty-resolver-dns-native-macos 工件,以便加载正确版本的本机库:
implementation("io.netty:netty-resolver-dns-native-macos:4.1.75.Final") {
artifact {
classifier = "osx-aarch_64"
}
}
For Maven the workaround looks like following:对于 Maven,解决方法如下所示:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-resolver-dns-native-macos</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-resolver-dns-native-macos</artifactId>
<version>4.1.73.Final</version>
<classifier>osx-aarch_64</classifier>
</dependency>
First exclude the referenced library.首先排除引用的库。 And then add it explicit with the classifier.
然后用分类器显式添加它。 Worked on M2 chip MacBook Pro 2022.
在 M2 芯片 MacBook Pro 2022 上工作。
For me was not enough to add the dependency as in the accepted answer.对我来说,在接受的答案中添加依赖项是不够的。 I am using Spring Boot and it still complains about missing:
我正在使用 Spring Boot,但它仍然抱怨缺少:
Caused by: java.io.FileNotFoundException: META INF/native/libnetty_resolver_dns_native_macos_aarch_64.jnilib
I needed to copy the我需要复制
/target/asr-reactive-example-1.0-SNAPSHOT.jar/BOOT-INF/classes/netty-resolver-dns-native-macos-4.1.75.Final-osx-aarch_64.jar/META-INF/native
folder, to:文件夹,到:
/target/asr-reactive-example-1.0-SNAPSHOT.jar/META-INF
which contains the file: libnetty_resolver_dns_native_macos_aarch_64.jnilib
其中包含文件:
libnetty_resolver_dns_native_macos_aarch_64.jnilib
For sure it can be automated with maven, but I don't know if this is the solution.当然它可以用maven自动化,但我不知道这是否是解决方案。
On a Macbook Pro with an Apple M1 Pro chip:在配备Apple M1 Pro芯片的Macbook Pro上:
# Groovy
runtimeOnly 'io.netty:netty-resolver-dns-native-macos:4.1.80.Final:osx-aarch_64'
# Kotlin
runtimeOnly("io.netty:netty-resolver-dns-native-macos:4.1.80.Final:osx-aarch_64")
# Maven
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-resolver-dns-native-macos</artifactId>
<version>4.1.80.Final</version>
<classifier>osx-aarch_64</classifier>
<scope>runtime</scope>
</dependency>
See newer versions of netty-resolver-dns-native-macos on mvnrepository.com在 mvnrepository.com 上查看较新版本的netty-resolver-dns-native-macos
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.