File tree Expand file tree Collapse file tree
java/com/baeldung/shutdown Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99
1010@ SpringBootApplication
1111public class Application {
12-
12+
1313 public static void main (String [] args ) {
1414
1515 SpringApplication .run (Application .class , args );
@@ -46,4 +46,5 @@ private static void writePID() {
4646 app .build ().addListeners (new ApplicationPidFileWriter ("./bin/shutdown.pid" ));
4747 app .run ();
4848 }
49+
4950}
Original file line number Diff line number Diff line change 11package com .baeldung .shutdown .shutdown ;
22
3+ import org .springframework .beans .BeansException ;
4+ import org .springframework .context .ApplicationContext ;
5+ import org .springframework .context .ApplicationContextAware ;
6+ import org .springframework .context .ConfigurableApplicationContext ;
7+ import org .springframework .web .bind .annotation .PostMapping ;
38import org .springframework .web .bind .annotation .RestController ;
49
510@ RestController
6- public class ShutdownController {
11+ public class ShutdownController implements ApplicationContextAware {
12+
13+ private ApplicationContext context ;
14+
15+ @ PostMapping ("/shutdownContext" )
16+ public void shutdownContext () {
17+ ((ConfigurableApplicationContext ) context ).close ();
18+ }
19+
20+ @ Override
21+ public void setApplicationContext (ApplicationContext ctx ) throws BeansException {
22+ this .context = ctx ;
23+
24+ }
725}
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ spring.jpa.hibernate.ddl-auto = update
99management.endpoints.jmx.domain =Spring Sample Application
1010management.endpoints.jmx.uniqueNames =true
1111
12+ management.endpoints.web.exposure.include =*
1213management.endpoint.shutdown.enabled =true
1314
1415# #jolokia.config.debug=true
@@ -27,8 +28,6 @@ info.app.description=This is my first spring boot application G1
2728info.app.version =1.0.0
2829info.java-vendor = ${java.specification.vendor}
2930
30- management.security.role =SUPERUSER
31-
3231logging.level.org.springframework =INFO
3332
3433# Servlet Configuration
You can’t perform that action at this time.
0 commit comments