Merge pull request #4285 from eugenp/custom-shutdown-endpoint

add custom shutdown endpoint
This commit is contained in:
Loredana Crusoveanu 2018-05-19 22:29:24 +03:00 committed by GitHub
commit 509e5064c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 4 deletions

View File

@ -46,4 +46,5 @@ public class Application {
app.build().addListeners(new ApplicationPidFileWriter("./bin/shutdown.pid"));
app.run();
}
}

View File

@ -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;
}
}

View File

@ -9,6 +9,7 @@ spring.jpa.hibernate.ddl-auto = update
management.endpoints.jmx.domain=Spring Sample Application
management.endpoints.jmx.uniqueNames=true
management.endpoints.web.exposure.include=*
management.endpoint.shutdown.enabled=true
##jolokia.config.debug=true
@ -27,8 +28,6 @@ info.app.description=This is my first spring boot application G1
info.app.version=1.0.0
info.java-vendor = ${java.specification.vendor}
management.security.role=SUPERUSER
logging.level.org.springframework=INFO
#Servlet Configuration