我有Spring 应用程序版本1.5.3. version
在我称为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)
...为什么叫两次?
发布于 2017-07-04 07:21:59
解决方案是将System.loadLibrary(Core.NATIVE_LIBRARY_NAME);放在自己的config类中:
@Configuration
public class LibLoading {
static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
}发布于 2018-03-28 09:20:14
Java异常处理- UnsatisfiedLinkError
static {
try {
// Attempt to load library.
System.loadLibrary("XXXXXX");
} catch (UnsatisfiedLinkError error) {
// Output expected UnsatisfiedLinkErrors.
} catch (Error | Exception error) {
// Output unexpected Errors and Exceptions.
}
}https://stackoverflow.com/questions/44880622
复制相似问题