Java Spring Boot-.dll已加载到另一个带有两个项目的类加载器中
我创建了两个springboot项目。 一个是Java Spring Boot-.dll已加载到另一个带有两个项目的类加载器中,java,spring,spring-boot,tomcat,Java,Spring,Spring Boot,Tomcat,我创建了两个springboot项目。 一个是测试项目,另一个是我的工作项目 测试项目: 使用System.load,我将.dll加载到dir .dll位于文件夹测试项目中 工作项目: 现在我正在尝试加载相同的.dll .dll放在我的工作文件夹中 所以每个项目都有自己的.dll 我总是犯错误: java.lang.UnsatifiedLinkErrordir已加载到另一个类加载器中 我必须从测试项目中“卸载”第一个.dll吗? tomcat是否在任何位置为我的测试项目会话加载.dll,这样我就
测试
项目,另一个是我的工作
项目
测试项目:
使用System.load,我将.dll加载到dir
.dll位于文件夹测试项目中
工作项目:
现在我正在尝试加载相同的.dll
.dll放在我的工作文件夹中
所以每个项目都有自己的.dll
我总是犯错误:
java.lang.UnsatifiedLinkErrordir已加载到另一个类加载器中
我必须从测试项目中“卸载”第一个.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集成到spring时出现,抛出java.lang.UnsatifiedLinkError异常:
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)
解决方案:我通过删除所有.dll文件修复了此问题。查找类路径所在的位置并将.dll粘贴到那里。您可以通过将.dll与System.load直接传递来直接加载.dll。如果使用类路径,请使用System.loadLibrary(“不带.dll的库的名称”)
@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);
}
}