formatting work
This commit is contained in:
@@ -4,14 +4,14 @@ import org.springframework.boot.autoconfigure.web.ErrorController;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
public class MyCustomErrorController implements ErrorController {
|
||||
|
||||
|
||||
private static final String PATH = "/error";
|
||||
|
||||
|
||||
public MyCustomErrorController() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@RequestMapping(value=PATH)
|
||||
|
||||
@RequestMapping(value = PATH)
|
||||
public String error() {
|
||||
return "Error heaven";
|
||||
}
|
||||
|
||||
@@ -8,12 +8,12 @@ public class ErrorController {
|
||||
|
||||
public ErrorController() {
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/400")
|
||||
String error400() {
|
||||
return "Error Code: 400 occured.";
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/errorHeaven")
|
||||
String errorHeaven() {
|
||||
return "You have reached the heaven of errors!!!";
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ public class MyServletContainerCustomizationBean implements EmbeddedServletConta
|
||||
public void customize(ConfigurableEmbeddedServletContainer container) {
|
||||
container.setPort(8084);
|
||||
container.setContextPath("/springbootapp");
|
||||
|
||||
|
||||
container.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/400"));
|
||||
container.addErrorPages(new ErrorPage("/errorHeaven"));
|
||||
}
|
||||
|
||||
+3
-4
@@ -6,9 +6,9 @@ import java.util.concurrent.ExecutorService;
|
||||
import org.springframework.boot.ExitCodeGenerator;
|
||||
|
||||
public class ExecutorServiceExitCodeGenerator implements ExitCodeGenerator {
|
||||
|
||||
|
||||
private ExecutorService executorService;
|
||||
|
||||
|
||||
public ExecutorServiceExitCodeGenerator(ExecutorService executorService) {
|
||||
}
|
||||
|
||||
@@ -20,8 +20,7 @@ public class ExecutorServiceExitCodeGenerator implements ExitCodeGenerator {
|
||||
executorService.shutdownNow();
|
||||
returnCode = 1;
|
||||
}
|
||||
}
|
||||
catch (SecurityException ex) {
|
||||
} catch (SecurityException ex) {
|
||||
returnCode = 0;
|
||||
}
|
||||
return returnCode;
|
||||
|
||||
@@ -10,34 +10,32 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class HelloWorldServlet extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public HelloWorldServlet() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
PrintWriter out = null;
|
||||
try {
|
||||
out = response.getWriter();
|
||||
out.println("HelloWorldServlet: GET METHOD");
|
||||
out.flush();
|
||||
}
|
||||
finally {
|
||||
if (!Objects.isNull(out))
|
||||
} finally {
|
||||
if (!Objects.isNull(out))
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
PrintWriter out = null;
|
||||
try {
|
||||
out = response.getWriter();
|
||||
out.println("HelloWorldServlet: POST METHOD");
|
||||
out.flush();
|
||||
}
|
||||
finally {
|
||||
if (!Objects.isNull(out))
|
||||
} finally {
|
||||
if (!Objects.isNull(out))
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
+6
-8
@@ -10,8 +10,8 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class SpringHelloWorldServlet extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public SpringHelloWorldServlet() {
|
||||
super();
|
||||
}
|
||||
@@ -22,9 +22,8 @@ public class SpringHelloWorldServlet extends HttpServlet {
|
||||
out = response.getWriter();
|
||||
out.println("SpringHelloWorldServlet: GET METHOD");
|
||||
out.flush();
|
||||
}
|
||||
finally {
|
||||
if (!Objects.isNull(out))
|
||||
} finally {
|
||||
if (!Objects.isNull(out))
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
@@ -35,9 +34,8 @@ public class SpringHelloWorldServlet extends HttpServlet {
|
||||
out = response.getWriter();
|
||||
out.println("SpringHelloWorldServlet: POST METHOD");
|
||||
out.flush();
|
||||
}
|
||||
finally {
|
||||
if (!Objects.isNull(out))
|
||||
} finally {
|
||||
if (!Objects.isNull(out))
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,13 +19,11 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({ "org.baeldung.common.error", "org.baeldung.common.error.controller",
|
||||
"org.baeldung.common.properties", "org.baeldung.common.resources", "org.baeldung.endpoints",
|
||||
"org.baeldung.service", "org.baeldung.monitor.jmx", "org.baeldung.service"})
|
||||
@ComponentScan({ "org.baeldung.common.error", "org.baeldung.common.error.controller", "org.baeldung.common.properties", "org.baeldung.common.resources", "org.baeldung.endpoints", "org.baeldung.service", "org.baeldung.monitor.jmx", "org.baeldung.service" })
|
||||
public class SpringBootApplication {
|
||||
|
||||
|
||||
private static ApplicationContext applicationContext;
|
||||
|
||||
|
||||
@Autowired
|
||||
private LoginService service;
|
||||
|
||||
@@ -34,21 +32,21 @@ public class SpringBootApplication {
|
||||
service.login("admin", "admin".toCharArray());
|
||||
return "TADA!!! You are in Spring Boot Actuator test application.";
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
applicationContext = SpringApplication.run(SpringBootApplication.class, args);
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public ExecutorService executorService() {
|
||||
return Executors.newFixedThreadPool(10);
|
||||
return Executors.newFixedThreadPool(10);
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public HelloWorldServlet helloWorldServlet() {
|
||||
return new HelloWorldServlet();
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public SpringHelloServletRegistrationBean servletRegistrationBean() {
|
||||
SpringHelloServletRegistrationBean bean = new SpringHelloServletRegistrationBean(new SpringHelloWorldServlet(), "/springHelloWorld/*");
|
||||
@@ -56,35 +54,35 @@ public class SpringBootApplication {
|
||||
bean.addInitParameter("message", "SpringHelloWorldServlet special message");
|
||||
return bean;
|
||||
}
|
||||
|
||||
/* @Bean
|
||||
|
||||
/* @Bean
|
||||
public JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory() {
|
||||
JettyEmbeddedServletContainerFactory jettyContainer = new JettyEmbeddedServletContainerFactory();
|
||||
jettyContainer.setPort(9000);
|
||||
jettyContainer.setContextPath("/springbootapp");
|
||||
return jettyContainer;
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public UndertowEmbeddedServletContainerFactory embeddedServletContainerFactory() {
|
||||
UndertowEmbeddedServletContainerFactory factory = new UndertowEmbeddedServletContainerFactory();
|
||||
factory.addBuilderCustomizers(new UndertowBuilderCustomizer() {
|
||||
|
||||
|
||||
@Override
|
||||
public void customize(io.undertow.Undertow.Builde builder) {
|
||||
builder.addHttpListener(8080, "0.0.0.0");
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
return factory;
|
||||
}*/
|
||||
|
||||
@Bean
|
||||
|
||||
@Bean
|
||||
@Autowired
|
||||
public ExecutorServiceExitCodeGenerator executorServiceExitCodeGenerator(ExecutorService executorService) {
|
||||
return new ExecutorServiceExitCodeGenerator(executorService);
|
||||
}
|
||||
|
||||
|
||||
public void shutDown(ExecutorServiceExitCodeGenerator executorServiceExitCodeGenerator) {
|
||||
SpringApplication.exit(applicationContext, executorServiceExitCodeGenerator);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user