一、编译环境:
Maven 3.6.3
JDK 11.0.12
MacBook Pro M1 Pro
IntelliJ IDEA 2022.2.1
二、报错信息
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tomcatServletWebServerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryConfiguration$EmbeddedTomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory]: Factory method 'tomcatServletWebServerFactory' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'httpTransportContext': Unsatisfied dependency expressed through field 'transportService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'defaultTransportService' defined in file [thingsboard/common/transport/transport-api/target/classes/org/thingsboard/server/common/transport/service/DefaultTransportService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'hashPartitionService' defined in file [thingsboard/common/queue/target/classes/org/thingsboard/server/queue/discovery/HashPartitionService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultTbServiceInfoProvider': Invocation of init method failed; nested exception is java.lang.UnsatisfiedLinkError: /private/var/folders/j8/1w9n0gnn0wg0ktbyh5m3574h0000gn/T/jna--1541425552/jna7791668774219771380.tmp: dlopen(/private/var/folders/j8/1w9n0gnn0wg0ktbyh5m3574h0000gn/T/jna--1541425552/jna7791668774219771380.tmp, 0x0001): tried: '/private/var/folders/j8/1w9n0gnn0wg0ktbyh5m3574h0000gn/T/jna--1541425552/jna7791668774219771380.tmp' (fat file, but missing compatible architecture (have 'i386,x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/private/var/folders/j8/1w9n0gnn0wg0ktbyh5m3574h0000gn/T/jna--1541425552/jna7791668774219771380.tmp' (no such file), '/private/var/folders/j8/1w9n0gnn0wg0ktbyh5m3574h0000gn/T/jna--1541425552/jna7791668774219771380.tmp' (fat file, but missing compatible architecture (have 'i386,x86_64', need 'arm64'))
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:165)Caused by: java.lang.UnsatisfiedLinkError: /private/var/folders/j8/1w9n0gnn0wg0ktbyh5m3574h0000gn/T/jna--1541425552/jna7791668774219771380.tmp: dlopen(/private/var/folders/j8/1w9n0gnn0wg0ktbyh5m3574h0000gn/T/jna--1541425552/jna7791668774219771380.tmp, 0x0001): tried: '/private/var/folders/j8/1w9n0gnn0wg0ktbyh5m3574h0000gn/T/jna--1541425552/jna7791668774219771380.tmp' (fat file, but missing compatible architecture (have 'i386,x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/private/var/folders/j8/1w9n0gnn0wg0ktbyh5m3574h0000gn/T/jna--1541425552/jna7791668774219771380.tmp' (no such file), '/private/var/folders/j8/1w9n0gnn0wg0ktbyh5m3574h0000gn/T/jna--1541425552/jna7791668774219771380.tmp' (fat file, but missing compatible architecture (have 'i386,x86_64', need 'arm64'))
at java.base/java.lang.ClassLoader$NativeLibrary.load0(Native Method)
at java.base/java.lang.ClassLoader$NativeLibrary.load(ClassLoader.java:2442)
at java.base/java.lang.ClassLoader$NativeLibrary.loadLibrary(ClassLoader.java:2498)
at java.base/java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2694)
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2627)
at java.base/java.lang.Runtime.load0(Runtime.java:768)
at java.base/java.lang.System.load(System.java:1837)
at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:851)
at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:826)
at com.sun.jna.Native.<clinit>(Native.java:140)
at com.sun.jna.Pointer.<clinit>(Pointer.java:41)
at com.sun.jna.Structure.<clinit>(Structure.java:2078)
at oshi.hardware.platform.mac.MacCentralProcessor.<clinit>(MacCentralProcessor.java:52)
at oshi.hardware.platform.mac.MacHardwareAbstractionLayer.getProcessor(MacHardwareAbstractionLayer.java:53)
at org.thingsboard.common.util.SystemUtil.getCpuUsage(SystemUtil.java:62)
at org.thingsboard.server.queue.discovery.DefaultTbServiceInfoProvider.getCurrentSystemInfoProto(DefaultTbServiceInfoProvider.java:121)
at org.thingsboard.server.queue.discovery.DefaultTbServiceInfoProvider.generateNewServiceInfoWithCurrentSystemInfo(DefaultTbServiceInfoProvider.java:113)
at org.thingsboard.server.queue.discovery.DefaultTbServiceInfoProvider.init(DefaultTbServiceInfoProvider.java:82)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:389)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:333)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:157)
... 93 common frames omitted
三、报错分析
oshi-core版本兼容性问题,导致缺失jna,无法读取操作系统和硬件信息
pom.xml(thingsboard)配置如下:
<groupId>com.github.dblock</groupId>
<artifactId>oshi-core</artifactId>
<version>${oshi.version}</version>
四、解决方案
1.修改pom.xml(thingsboard)文件
<dependency> <groupId>com.github.oshi</groupId> <artifactId>oshi-core</artifactId> <version>${oshi.version}</version> </dependency>
注: oshi.version 最新版为 6.4.2 (https://mvnrepository.com/artifact/com.github.oshi/oshi-core)
2.修改pom.xml(util)文件 路径:common/util/pom.xml
<dependency> <groupId>com.github.oshi</groupId> <artifactId>oshi-core</artifactId> </dependency>
3.修改SystemUtil文件,路径:src/main/java/org/thingsboard/common/util/SystemUtil.java
修改getSystemCpuLoad()方法(CentralProcessor (oshi-core 6.4.2 API))
加载Maven修改,启动服务,运行正常。