From ca2da8b36b6cf13c5b885ff7e74bc22d3576f6c7 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sat, 18 Jun 2016 22:04:49 +0200 Subject: [PATCH] WIP: welcom + error - einfacherer Weg zur eigenen Fehlerseite --- .../java/de/juplo/thymeproxy/Application.java | 40 +++---------------- 1 file changed, 5 insertions(+), 35 deletions(-) diff --git a/src/main/java/de/juplo/thymeproxy/Application.java b/src/main/java/de/juplo/thymeproxy/Application.java index 0840e95..ff5174a 100644 --- a/src/main/java/de/juplo/thymeproxy/Application.java +++ b/src/main/java/de/juplo/thymeproxy/Application.java @@ -2,28 +2,23 @@ package de.juplo.thymeproxy; import de.juplo.thymeleaf.JuploDialect; import java.util.HashMap; +import java.util.Locale; import java.util.Map; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import org.apache.http.impl.client.CloseableHttpClient; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.web.BasicErrorController; -import org.springframework.boot.autoconfigure.web.ErrorAttributes; -import org.springframework.boot.autoconfigure.web.ErrorController; -import org.springframework.boot.autoconfigure.web.ErrorProperties; import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.context.annotation.Bean; import org.springframework.core.Ordered; import org.springframework.core.env.Environment; -import org.springframework.http.MediaType; -import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.View; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.mvc.UrlFilenameViewController; import org.thymeleaf.resourceresolver.IResourceResolver; import org.thymeleaf.resourceresolver.UrlResourceResolver; +import org.thymeleaf.spring4.view.ThymeleafViewResolver; import org.thymeleaf.templateresolver.TemplateResolver; @@ -117,9 +112,9 @@ public class Application extends WebMvcConfigurerAdapter } @Bean - public ErrorController errorController(ErrorAttributes errorAttributes) + public View error(ThymeleafViewResolver resolver) throws Exception { - return new CustomErrorController(errorAttributes, properties.getError()); + return resolver.resolveViewName("templates/error", Locale.getDefault()); } @@ -134,29 +129,4 @@ public class Application extends WebMvcConfigurerAdapter { SpringApplication.run(Application.class, args); } - - - static class CustomErrorController extends BasicErrorController - { - CustomErrorController( - ErrorAttributes errorAttributes, - ErrorProperties errorProperties - ) - { - super(errorAttributes, errorProperties); - } - - - @Override - public ModelAndView errorHtml(HttpServletRequest request, HttpServletResponse response) - { - response.setStatus(getStatus(request).value()); - Map model = - getErrorAttributes( - request, - isIncludeStackTrace(request, MediaType.TEXT_HTML) - ); - return new ModelAndView("templates/error", model); - } - } } \ No newline at end of file -- 2.20.1