From: Kai Moritz Date: Sat, 18 Jun 2016 21:43:10 +0000 (+0200) Subject: WIP: welcom + error - 404 anstatt 500 X-Git-Tag: alt~14 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=22713c1dd38e87591230b5b03d8fd6abb33e8cf1;p=maven-thymeleaf-skin WIP: welcom + error - 404 anstatt 500 --- diff --git a/src/main/java/de/juplo/thymeproxy/Application.java b/src/main/java/de/juplo/thymeproxy/Application.java index 7eb7333..48bea7d 100644 --- a/src/main/java/de/juplo/thymeproxy/Application.java +++ b/src/main/java/de/juplo/thymeproxy/Application.java @@ -118,9 +118,9 @@ public class Application extends WebMvcConfigurerAdapter } @Bean - public ExceptionMappings exceptionMappings() + public DefaultExceptionHandler defaultExceptionHandler() { - return new ExceptionMappings(); + return new DefaultExceptionHandler(); } diff --git a/src/main/java/de/juplo/thymeproxy/DefaultExceptionHandler.java b/src/main/java/de/juplo/thymeproxy/DefaultExceptionHandler.java new file mode 100644 index 0000000..6fb89b5 --- /dev/null +++ b/src/main/java/de/juplo/thymeproxy/DefaultExceptionHandler.java @@ -0,0 +1,33 @@ +package de.juplo.thymeproxy; + + +import javax.servlet.http.HttpServletRequest; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.servlet.ModelAndView; +import org.thymeleaf.exceptions.TemplateInputException; + + + +/** + * + * @author Kai Moritz + */ +@ControllerAdvice +public class DefaultExceptionHandler +{ + @ResponseStatus(HttpStatus.NOT_FOUND) + @ExceptionHandler(value = TemplateInputException.class) + public ModelAndView templateInputExceptionHandler( + HttpServletRequest request, + TemplateInputException e + ) + { + ModelAndView mav = new ModelAndView("templates/404"); + mav.addObject("template", e.getTemplateName()); + mav.addObject("uri", request.getRequestURI()); + return mav; + } +} diff --git a/src/main/java/de/juplo/thymeproxy/ExceptionMappings.java b/src/main/java/de/juplo/thymeproxy/ExceptionMappings.java deleted file mode 100644 index a265e3f..0000000 --- a/src/main/java/de/juplo/thymeproxy/ExceptionMappings.java +++ /dev/null @@ -1,33 +0,0 @@ -package de.juplo.thymeproxy; - - -import javax.servlet.http.HttpServletRequest; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.servlet.ModelAndView; -import org.thymeleaf.exceptions.TemplateInputException; - - - -/** - * - * @author Kai Moritz - */ -@ControllerAdvice -public class ExceptionMappings -{ - @ResponseStatus(HttpStatus.NOT_FOUND) - @ExceptionHandler(value = TemplateInputException.class) - public ModelAndView templateInputExceptionHandler( - HttpServletRequest request, - TemplateInputException e - ) - { - ModelAndView mav = new ModelAndView("templates/404"); - mav.addObject("template", e.getTemplateName()); - mav.addObject("uri", request.getRequestURI()); - return mav; - } -}