我正在尝试使用 NotFoundExceptionMapper 处理此问题,但它没有调用该类。
public class NotFoundExceptionMapper implements ExceptionMapper<NotFoundException> {
@Context
HttpServletRequest request;
@Context
HttpServletResponse response;
public Response toResponse(NotFoundException e) {
String requestURI1 = request.getPathInfo();
String requestURI = request.getQueryString();
final long id = ThreadLocalRandom.current().nextLong();
if (requestURI1.startsWith("/app")){
Configuration configuration = null;
try {
configuration = ApplicationProperties.get();
} catch (AtlasException ex) {
ex.printStackTrace();
}
String baseUrl = Objects.requireNonNull(configuration).getString(AtlasConstants.ATLAS_REST_ADDRESS_KEY);
requestURI1 = requestURI1.replace("/app","/index.html?path=");
return Response
.temporaryRedirect(URI.create(baseUrl + requestURI1 + "?" + requestURI))
.build();
} else {
return Response
.status((Response.StatusType) HttpResponseStatus.NOT_FOUND)
.entity(ExceptionMapperUtil.formatErrorMessage(id, e))
.build();
}
}
}
这是我的代码。我们正在尝试删除“#!” 从网址。请不要建议我@controller。404 上哪个班?