BAEL-1800 (#4377)
* BAEL-1800 - Code for http://www.baeldung.com/spring-boot-starters and http://www.baeldung.com/spring-mvc-custom-data-binder * BAEL-1800 - Code for http://www.baeldung.com/maven-webjars and http://www.baeldung.com/deployable-fat-jar-spring-boot * BAEL-1800 - Code for http://www.baeldung.com/spring-boot-shutdown * BAEL-1800 - Code for http://www.baeldung.com/spring-boot-shutdown * BAEL-1800 - Code for http://www.baeldung.com/spring-boot-dependency-management-custom-parent
This commit is contained in:
committed by
maibin
parent
8e36e2b155
commit
6e94f0343c
@@ -1,50 +0,0 @@
|
||||
package com.baeldung.shutdown;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.context.ApplicationPidFileWriter;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
SpringApplication.run(Application.class, args);
|
||||
// closeApplication();
|
||||
// exitApplication();
|
||||
// writePID();
|
||||
|
||||
}
|
||||
|
||||
private static void closeApplication() {
|
||||
|
||||
ConfigurableApplicationContext ctx = new SpringApplicationBuilder(Application.class).web(WebApplicationType.NONE).run();
|
||||
System.out.println("Spring Boot application started");
|
||||
ctx.getBean(TerminateBean.class);
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
private static void exitApplication() {
|
||||
|
||||
ConfigurableApplicationContext ctx = new SpringApplicationBuilder(Application.class).web(WebApplicationType.NONE).run();
|
||||
|
||||
int exitCode = SpringApplication.exit(ctx, () -> {
|
||||
// return the error code
|
||||
return 0;
|
||||
});
|
||||
|
||||
System.out.println("Exit Spring Boot");
|
||||
|
||||
System.exit(exitCode);
|
||||
}
|
||||
|
||||
private static void writePID() {
|
||||
SpringApplicationBuilder app = new SpringApplicationBuilder(Application.class).web(WebApplicationType.NONE);
|
||||
app.build().addListeners(new ApplicationPidFileWriter("./bin/shutdown.pid"));
|
||||
app.run();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.baeldung.shutdown;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = "com.baeldung.shutdown")
|
||||
public class ShutdownConfig {
|
||||
|
||||
@Bean
|
||||
public TerminateBean getTerminateBean() {
|
||||
return new TerminateBean();
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.baeldung.shutdown;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
public class TerminateBean {
|
||||
|
||||
@PreDestroy
|
||||
public void onDestroy() throws Exception {
|
||||
System.out.println("Spring Container is destroyed!");
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
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 implements ApplicationContextAware {
|
||||
|
||||
private ApplicationContext context;
|
||||
|
||||
@PostMapping("/shutdownContext")
|
||||
public void shutdownContext() {
|
||||
((ConfigurableApplicationContext) context).close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext ctx) throws BeansException {
|
||||
this.context = ctx;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.baeldung.webjar;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@Controller
|
||||
public class TestController {
|
||||
|
||||
@GetMapping(value = "/")
|
||||
public String welcome(Model model) {
|
||||
return "index";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.baeldung.webjar;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class WebjarsdemoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(WebjarsdemoApplication.class, args);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user