如何在apache commons daemon jsvc启动时设置嵌套类加载?

Pau*_*mas 8 jsvc spring-boot

我想使用jsvc启动我的spring启动应用程序,因为它已经在目标系统上,另一种方法是花时间调试shell脚本以获取边缘情况.我已经实现了守护进程接口,因此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();
  }
}
Run Code Online (Sandbox Code Playgroud)

这个错误

java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
Run Code Online (Sandbox Code Playgroud)

小智 1

我已经解决了这个问题。

我必须生产阴影罐而不是胖罐。然后我没有使用 JarLoader,而是直接将主类更改为我的主类。如果原始海报为“申请”类。