Как вернуть jsp с помощью настраиваемого ErrorController? - PullRequest
0 голосов
/ 07 мая 2020

Я пытаюсь вернуть настраиваемую страницу ошибки. Следуя этому руководству , я создал свой контроллер ошибок следующим образом:

@Controller
public class ErrorResource implements ErrorController  {

    @Override
    public String getErrorPath() {
        return "/error";
    }

    @RequestMapping("/error")
    public Response handleError(HttpServletRequest request) {
        System.out.println("error handler called");
        try {
            Map<String, Object> model = new HashMap<>();
            return Response.ok(new Viewable("/path/to/jsp", model)).build();
        } catch (Exception e) {
            System.out.println("Exception thrown: " + e);
            throw new RuntimeException();
        }
    }
}

Теперь вместо страницы ошибок белой метки, например:

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Wed May 06 19:02:36 PDT 2020
There was an unexpected error (type=Internal Server Error, status=500).

I вместо этого посмотрите это:

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

null
There was an unexpected error (type=null, status=null).

В моих обычных файлах я могу просто вернуть jsp. Например, для меня отлично работает следующее:

@Path("/")
public class Resource {

    @Context
    private HttpServletResponse response;

    @GET
    @Path("/swift/containers")
    @Consumes("application/x-www-form-urlencoded")
    @Produces({ "text/html" })
    public Response getContainersPage() {
        Map<String, Object> model = new HashMap<>();
        model.put("containers", getContainers());
        return Response.ok(new Viewable("/path/to/jsp", model)).build();
    }
}

Я подтвердил, что метод вызывается, потому что печатается «вызван обработчик ошибок». Сообщение об исключении не выводится.

Что мне не хватает?

1 Ответ

0 голосов
/ 07 мая 2020
• 1000 1005 * и пом. xml вот так?
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
...