|
| 1 | +package org.baeldung.main; |
| 2 | + |
| 3 | +import java.util.concurrent.ExecutorService; |
| 4 | +import java.util.concurrent.Executors; |
| 5 | + |
| 6 | +import org.baeldung.common.error.SpringHelloServletRegistrationBean; |
| 7 | +import org.baeldung.common.resources.ExecutorServiceExitCodeGenerator; |
| 8 | +import org.baeldung.controller.servlet.HelloWorldServlet; |
| 9 | +import org.baeldung.controller.servlet.SpringHelloWorldServlet; |
| 10 | +import org.baeldung.service.LoginService; |
| 11 | +import org.springframework.beans.factory.annotation.Autowired; |
| 12 | +import org.springframework.boot.SpringApplication; |
| 13 | +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; |
| 14 | +import org.springframework.context.ApplicationContext; |
| 15 | +import org.springframework.context.annotation.Bean; |
| 16 | +import org.springframework.context.annotation.ComponentScan; |
| 17 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 18 | +import org.springframework.web.bind.annotation.RestController; |
| 19 | + |
| 20 | +@RestController |
| 21 | +@EnableAutoConfiguration |
| 22 | +@ComponentScan({ "org.baeldung.common.error", "org.baeldung.common.error.controller", |
| 23 | + "org.baeldung.common.properties", "org.baeldung.common.resources", "org.baeldung.endpoints", |
| 24 | + "org.baeldung.service", "org.baeldung.monitor.jmx", "org.baeldung.service"}) |
| 25 | +public class SpringBootApplication { |
| 26 | + |
| 27 | + private static ApplicationContext applicationContext; |
| 28 | + |
| 29 | + @Autowired |
| 30 | + private LoginService service; |
| 31 | + |
| 32 | + @RequestMapping("/") |
| 33 | + String home() { |
| 34 | + service.login("admin", "admin".toCharArray()); |
| 35 | + return "TADA!!! You are in Spring Boot Actuator test application."; |
| 36 | + } |
| 37 | + |
| 38 | + public static void main(String[] args) { |
| 39 | + applicationContext = SpringApplication.run(SpringBootApplication.class, args); |
| 40 | + } |
| 41 | + |
| 42 | + @Bean |
| 43 | + public ExecutorService executorService() { |
| 44 | + return Executors.newFixedThreadPool(10); |
| 45 | + } |
| 46 | + |
| 47 | + @Bean |
| 48 | + public HelloWorldServlet helloWorldServlet() { |
| 49 | + return new HelloWorldServlet(); |
| 50 | + } |
| 51 | + |
| 52 | + @Bean |
| 53 | + public SpringHelloServletRegistrationBean servletRegistrationBean() { |
| 54 | + SpringHelloServletRegistrationBean bean = new SpringHelloServletRegistrationBean(new SpringHelloWorldServlet(), "/springHelloWorld/*"); |
| 55 | + bean.setLoadOnStartup(1); |
| 56 | + bean.addInitParameter("message", "SpringHelloWorldServlet special message"); |
| 57 | + return bean; |
| 58 | + } |
| 59 | + |
| 60 | +/* @Bean |
| 61 | + public JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory() { |
| 62 | + JettyEmbeddedServletContainerFactory jettyContainer = new JettyEmbeddedServletContainerFactory(); |
| 63 | + jettyContainer.setPort(9000); |
| 64 | + jettyContainer.setContextPath("/springbootapp"); |
| 65 | + return jettyContainer; |
| 66 | + } |
| 67 | +
|
| 68 | + @Bean |
| 69 | + public UndertowEmbeddedServletContainerFactory embeddedServletContainerFactory() { |
| 70 | + UndertowEmbeddedServletContainerFactory factory = new UndertowEmbeddedServletContainerFactory(); |
| 71 | + factory.addBuilderCustomizers(new UndertowBuilderCustomizer() { |
| 72 | +
|
| 73 | + @Override |
| 74 | + public void customize(io.undertow.Undertow.Builde builder) { |
| 75 | + builder.addHttpListener(8080, "0.0.0.0"); |
| 76 | + } |
| 77 | +
|
| 78 | + }); |
| 79 | + return factory; |
| 80 | + }*/ |
| 81 | + |
| 82 | + @Bean |
| 83 | + @Autowired |
| 84 | + public ExecutorServiceExitCodeGenerator executorServiceExitCodeGenerator(ExecutorService executorService) { |
| 85 | + return new ExecutorServiceExitCodeGenerator(executorService); |
| 86 | + } |
| 87 | + |
| 88 | + public void shutDown(ExecutorServiceExitCodeGenerator executorServiceExitCodeGenerator) { |
| 89 | + SpringApplication.exit(applicationContext, executorServiceExitCodeGenerator); |
| 90 | + } |
| 91 | + |
| 92 | +} |
0 commit comments