只是为了澄清这只发生在M1 Mac上,英特尔版本似乎没有这个问题。
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
项目图表
问题:
尝试通过API网关访问其中一个微服务时引发java.lang.UnsatisfiedLinkError
异常错误。例如,http://localhost:8082/API-USER/users/status/ok
将引发此异常错误。return
值正确,API网关继续运行,但出现令人讨厌的异常。
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
问题
有人知道如何减少这个错误吗?
"我累了..."
- https://github.com/netty/netty-tcnative/issues/576
- https://github.com/netty/netty-tcnative/issues/343
这两个链接都建议添加netty-tcnative-boringssl-static
依赖项,但效果不佳....
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
5条答案
按热度按时间cbwuti441#
在GitHub上发现问题:https://github.com/netty/netty/issues/11020
获取最新版本:https://mvnrepository.com/artifact/io.netty/netty-resolver-dns-native-macos
仍然没有解释为什么会出现这个问题,但在这里,它为我修复了这个问题:
Maven
grad尔
6pp0gazn2#
您必须将适当的分类器添加到netty-resolver-dns-native-macos工件中,以便加载本机库的适当版本:
6mw9ycah3#
在配备Apple M1 Pro芯片的MacBook Pro上:
第一个
请在www.example.com上查看netty-resolver-dns-native-macos的较新版本mvnrepository.com
t8e9dugd4#
编辑
在尝试了上面的解决方案后,我发现它并不适合我,并且用了一个愚蠢的冗长的解决方案进行了修复,我意识到我的服务器是用Tomcat启动的,因为它引入了一个可传递的依赖项org.apache.tomcat.embed:tomcat-embed-core。
我不会删除这篇文章,因为其他人看到了异常,但没有观察到他们的服务器是用Tomcat启动的。
对我来说,像在接受的答案中那样添加依赖性是不够的。我正在使用Sping Boot ,它仍然抱怨缺少:
Caused by: java.io.FileNotFoundException: META INF/native/libnetty_resolver_dns_native_macos_aarch_64.jnilib
我需要复制
/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
文件夹中,到:
/target/asr-reactive-example-1.0-SNAPSHOT.jar/META-INF
其中包含文件:
libnetty_resolver_dns_native_macos_aarch_64.jnilib
当然,它可以自动与maven,但我不知道这是否是解决方案。
编辑日期:
好吧,我不知道为什么接受的答案工程为其他人,但对我来说,这是真的很烦人,看到启动时的错误,我不想禁用MacOSDnsServerAddressStreamProvider或谁是日志记录错误的日志记录。
在我使用netty和jdk中的调试器进入之后,我发现它尝试使用
System.loadLibrary()
加载它:load with System
搜索范围:
System search
以及:
User search
当然,它不存在。然后,它尝试在类路径中查找它,但失败了:
classpath1
classpath2
在我将库复制到
META-INF/native
之后,它使用类路径创建库(在System/User位置失败之后),然后将库复制到工作目录的根目录,最后成功,因为System.loadLibrary()
在“."中找到了它:found-it
现在,为了自动复制文件,我做了一些技巧:
设置某些版本:
然后包含相依性:
然后复制本机库:
但仅当操作系统架构为ARM 64时(参见
<skip>${skip.aarch64.copy}</skip>
):对于上面“os.detected.arch”属性,我使用了:
我知道。非常复杂的解决方案。如果有人有其他的解决方案,请张贴在这里。
3bygqnnd5#
对于Maven,解决方法如下所示:
首先排除引用的库。然后使用分类器将其显式添加。适用于M2芯片MacBook Pro 2022。