add custom shutdown endpoint
This commit is contained in:
@@ -9,7 +9,7 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
SpringApplication.run(Application.class, args);
|
||||
@@ -46,4 +46,5 @@ public class Application {
|
||||
app.build().addListeners(new ApplicationPidFileWriter("./bin/shutdown.pid"));
|
||||
app.run();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,25 @@
|
||||
package com.baeldung.shutdown.shutdown;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class ShutdownController {
|
||||
public class ShutdownController implements ApplicationContextAware {
|
||||
|
||||
private ApplicationContext context;
|
||||
|
||||
@PostMapping("/shutdownContext")
|
||||
public void shutdownContext() {
|
||||
((ConfigurableApplicationContext) context).close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext ctx) throws BeansException {
|
||||
this.context = ctx;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user