SpringBoot:运行的System.loadLibrary两次
问题描述:
我春天引导应用程序版本1.5.3.RELEASESpringBoot:运行的System.loadLibrary两次
在主类我称之为的System.loadLibrary:
@SpringBootApplication
@EnableScheduling
public class BlaApplication {
static {
System.out.println("xxxxxxxxxxxxxxxxxx Loading Lib");
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
public static void main(String[] args) {
SpringApplication.run(BlaApplication.class, args);
}
}
当应用程序启动System.loadLibrary被调用两次:
xxxxxxxxxxxxxxxxxx Loading Lib
11:10:51.766 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
11:10:51.771 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-starter/target/classes/, /spring-boot-autoconfigure/target/classes/, /spring-boot-starter-[\w-]+/, /spring-boot/target/classes/, /spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/]
11:10:51.771 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : [file:/Users/tomas/workspace/formater/formater-backend/target/classes/]
xxxxxxxxxxxxxxxxxx Loading Lib
Exception in thread "restartedMain" java.lang.UnsatisfiedLinkError: Native Library /usr/local/Cellar/opencv/2.4.13.2/share/OpenCV/java/libopencv_java2413.dylib already loaded in another classloader
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1907)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at com.martoma.BlaApplication.<clinit>(BlaApplication.java:16)
...
为什么它被调用两次?
答
解决的办法是把System.loadLibrary(Core.NATIVE_LIBRARY_NAME);在它自己的配置类中:
@Configuration
public class LibLoading {
static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
}
+0
谢谢你 – mesutpiskin
可能有另一个类在运行时加载库。如果你删除这个加载,库是否加载? – davidxxx
但问题是,这个特定的静态块运行两次 - 如果我把记录器上面System.loadLibrary(...)我有2个日志在控制台 –
如果我删除System.loadLibrary(...),lib不加载应用程序和OpenCV上的任何调用失败 –