我想使用 jsvc 来启动我的 spring boot 应用程序,因为它已经在目标系统上,而另一种方法是花时间为边缘情况调试 shell 脚本。我已经实现了 Daemon 接口,以便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