簡體   English   中英

自定義ExceptionMapper無法在Spring + Jersey + Jetty中運行

[英]Custom ExceptionMapper not working in Spring + Jersey + Jetty

我的異常映射器如下所示

@Provider
public class DAExceptionMapper implements ExceptionMapper<DAException> {
    @Override
    public @ResponseBody Response toResponse(DAException exception) {
    }
}

public class DAException extends Exception {
}

我在Jetty 8.1.14上使用Spring 3.2.5和Jersey 2.15。

我找不到為什么我的異常映射器沒有注冊Spring。 當我在我的應用程序中拋出自定義DAException時,我得到500。 我在https://java.net/jira/browse/JERSEY-2063中嘗試了所有解決方案。 他們都沒有工作。

我目前在spring context xml中注冊的異常沒有任何bean。 我的應用程序沒有通過程序設置資源。

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is DAException [responseStatus=Unauthorized, errorMessage=ErrorMessage [errorMessage=User is not allowed to access this resource.], errorDescription=User is not allowed to access this resource.]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)

你實現了toResponse方法嗎?

@Provider
public class DAExceptionMapper implements
        ExceptionMapper<DAException> {
    @Override
    public Response toResponse(DAException ex) {
        return Response.status(404).entity(ex.getMessage()).type("text/plain")
                .build();
    }
}

還有這個,但聽起來這與球衣版本> 2.5 toResponse在球衣中有關ExceptionMapper不會被調用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM