【问题标题】:Spring Boot - .dll already loaded in another classloader with two projectsSpring Boot - .dll 已经加载到另一个具有两个项目的类加载器中
【发布时间】:2018-09-12 18:29:45
【问题描述】:

我创建了两个 Spring Boot 项目。 一个是test 项目,另一个是我的working 项目

测试项目:

使用 System.load 我将 .dll 加载到目录 .dll 位于文件夹测试项目中

工作项目:

现在我正在尝试加载相同的 .dll .dll 放在我的工作文件夹中

所以每个项目都有自己的.dll

我总是出错:

java.lang.UnsatisfiedLinkError dir 已在另一个类加载器中加载

我必须从测试项目中“卸载”第一个 .dll 吗?

tomcat 是否在任何位置为我的测试项目会话加载 .dll,这样我就无法为我的工作项目再次加载 .dll?

或者

如何加载“已经加载”的库?

Exception in thread "restartedMain" java.lang.UnsatisfiedLinkError: Native Library C:\Dev\workspace\lightserver\src\main\libs\huesdk.dll already loaded in another classloader
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1907)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1824)
at java.lang.Runtime.load0(Runtime.java:809)
at java.lang.System.load(System.java:1086)

【问题讨论】:

  • 解决方案:我通过删除所有 .dll 文件解决了这个问题。查找您的类路径的位置并将 .dll 粘贴到那里。您可以通过使用 System.load 直接传递 .dll 来直接加载它。如果您使用类路径,请使用 System.loadLibrary("name of the library without .dll")

标签: java spring spring-boot tomcat


【解决方案1】:

在将外部dll集成到spring时出现,抛出java.lang.UnsatisfiedLinkErrorabnormal:

Exception in thread "restartedMain" java.lang.UnsatisfiedLinkError: Native Library *\opencv_java400.dll 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.jinbill.ocr.OcrApplication.<clinit>(OcrApplication.java:22)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:15)

使用spring-boot-devtools,springboot会在运行过程中重新加载上下文(启动时会重新加载一次),所以会提示加载链接库,直接在加载的动态链接库所在位置加上try赶上就行:

@SpringBootApplication
public class AppApplication {
    static {
        try {
            System.loadLibrary(NATIVE_LIBRARY_NAME);
        } catch (UnsatisfiedLinkError ignore) {
            / / After using spring-dev-tools, the context will be loaded multiple times, so here will throw the exception that the link library has been loaded.
            / / If there is this exception, the link library has been loaded, you can directly swallow the exception.
        }
    }
    
    public static void main(String[] args) {
        SpringApplication.run(AppApplication.class, args);
    }
}

【讨论】:

    猜你喜欢
    • 2010-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多