我有一个Spring Boot应用程序,该应用程序在启动时会加载一些DLL。现在,当某些情况发生时,我需要以编程方式重新启动应用程序。
我正在使用内置的Spring Boot执行器restartendpoint重新启动应用程序。该应用程序运行良好,直到再次开始加载DLL,这时它失败并显示以下错误。
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dealerConnection' defined in file [C:\Users\xxx\IdeaProjects\atlas\mw-service\out\production\classes\com\mlp\atlas\mwservice\mw\connect\DealerConnection.class]: Bean instantiation via constructor failed; nested exception is java.lang.UnsatisfiedLinkError: Native Library C:\Users\xxx\IdeaProjects\atlas\mw-service\lib-bin\sw_boost_thread_lib.dll already loaded in another classloader
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:304)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:285)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1308)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1154)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1244)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1164)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760)
... 19 common frames omitted
Caused by: java.lang.UnsatisfiedLinkError: Native Library C:\Users\xxx\IdeaProjects\atlas\mw-service\lib-bin\sw_boost_thread_lib.dll already loaded in another classloader
这是重新启动应用程序所需的简单代码。
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.restart.RestartEndpoint;
import org.springframework.stereotype.Service;
@Service
public class RestartService {
@Autowired
private RestartEndpoint restartEndpoint;
public void restartApp() {
restartEndpoint.restart();
}
}
此代码将DLL加载到内存中-
static {
if (SystemUtils.IS_OS_WINDOWS) {
log.info("Application running on a Windows Platform. Loading MarkitWire dlls first");
loadLibrary("sw_boost_thread_lib");
loadLibrary("sw_libeay32");
loadLibrary("sw_ssleay32");
loadLibrary("sw-xerces-c_3_1");
loadLibrary("sw-XalanMessages_1_11");
loadLibrary("sw-Xalan-C_1_11");
loadLibrary("sw_api");
loadLibrary("SWAPILink");
log.info("Completed loading of dlls");
} else {
log.info("Application running on a Non-Windows Platform. Loading .so file");
loadLibrary("SWAPILink");
}
对于如何先卸载DLL,然后重新启动Spring Boot应用程序,我一无所知(但我认为无法卸载DLL-操作系统会自动执行此操作), 要么 再次加载时检查先前加载的DLL。
或者Spring Boot Actuator Restart是否还有其他方法可以完全杀死应用程序,然后重新启动它?
感谢您的帮助。