我想使用 jsvc 来启动我的 spring boot 应用程序,因为它已经在目标系统上,而另一种方法是花时间为边缘情况调试 shell 脚本。我已经实现了 Daemon 接口(interface),以便 SpringApplication.run()
在 Daemon.start()
中调用但是找不到嵌套的 jar ,因为我绕过了 JarLoader
.
有没有办法以编程方式设置正确的类加载器等?
@Configuration
@EnableAutoConfiguration
@ComponentScan
@EnableConfigurationProperties
public class Application implements Daemon {
private ConfigurableApplicationContext ctx;
private String[] args;
@Override
public void init(DaemonContext context) throws Exception {
args = context.getArguments();
}
@Override
public void start() throws Exception {
ctx = SpringApplication.run(Application.class, args);
}
@Override
public void stop() throws Exception {
ctx.stop();
}
@Override
public void destroy() {
ctx.close();
}
// Main - mostly for development.
public static void main(String[] args) throws Exception {
System.err.println("WARNING - running as current user");
DaemonLoader.Context ctx = new DaemonLoader.Context();
Application app = new Application();
ctx.setArguments(args);
app.init(ctx);
app.start();
}
}
这与错误
java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
最佳答案
我已经解决了这个问题。
我不得不生产带阴影的 jar 而不是 fat jar 子。
然后,我没有使用 JarLoader,而是将主类直接更改为我的主类。如果是“应用程序”类的原始海报。
关于spring-boot - apache commons daemon jsvc启动时如何设置嵌套类加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25664871/