org.springframework.daemon.SpringBootDaemon Maven / Gradle / Ivy
package org.springframework.daemon;
import java.util.Arrays;
import org.apache.commons.daemon.Daemon;
import org.apache.commons.daemon.DaemonContext;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.util.ClassUtils;
public class SpringBootDaemon implements Daemon {
private Class springBootApp;
private ConfigurableApplicationContext content;
@Override
public void init(DaemonContext context) throws Exception {
System.out.println("Daemon initialized with arguments [" + Arrays.toString(context.getArguments()) + "]");
this.springBootApp = ClassUtils.resolveClassName(context.getArguments()[0], SpringBootDaemon.class.getClassLoader());
}
@Override
public void start() throws Exception {
System.out.println("Starting Spring Boot application [" + this.springBootApp.getName() + "]");
this.content = SpringApplication.run(springBootApp);
}
@Override
public void stop() throws Exception {
System.out.println("Stopping Spring Boot application [" + this.springBootApp.getName() + "]");
this.content.close();
}
@Override
public void destroy() {
}
}