首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SpringBoot: System.loadLibrary运行两次

SpringBoot: System.loadLibrary运行两次
EN

Stack Overflow用户
提问于 2017-07-03 08:09:57
回答 2查看 1.7K关注 0票数 1

我有Spring 应用程序版本1.5.3. version

在我称为System.loadLibrary:的主要类中

代码语言:javascript
复制
@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被调用了两次

代码语言:javascript
复制
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)
...

为什么叫两次?

EN

回答 2

Stack Overflow用户

发布于 2017-07-04 07:21:59

解决方案是将System.loadLibrary(Core.NATIVE_LIBRARY_NAME);放在自己的config类中:

代码语言:javascript
复制
@Configuration
public class LibLoading {
    static {
       System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    }
}
票数 2
EN

Stack Overflow用户

发布于 2018-03-28 09:20:14

Java异常处理- UnsatisfiedLinkError

代码语言:javascript
复制
static {

     try {
            // Attempt to load library.
            System.loadLibrary("XXXXXX"); 
        } catch (UnsatisfiedLinkError error) {
            // Output expected UnsatisfiedLinkErrors.
        } catch (Error | Exception error) {
            // Output unexpected Errors and Exceptions.
        }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44880622

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档