팀과 함께 Jersey 웹 응용 프로그램에서 작업 할 때 프로젝트가 점점 더 커짐에 따라 Tomcat에서 Grizzly로 전환하여 프로젝트의 일부를 다른 포트 번호 . 내가 지금 발견 한 것은, 우리가 가지고있는 커스텀 예외 처리가 지금은 작동하지 않고 대신에 항상 그리즐리 html 페이지를 얻는다는 것입니다.Grizzly 컨테이너에서 JAX-RS Exception Mapper가 작동하지 않습니다.
예 예외 :
public class DataNotFoundException extends RuntimeException{
private static final long serialVersionUID = -1622261264080480479L;
public DataNotFoundException(String message) {
super(message);
System.out.println("exception constructor called"); //this prints
}
}
매퍼 :
@Provider
public class DataNotFoundExceptionMapper implements ExceptionMapper<DataNotFoundException>{
public DataNotFoundExceptionMapper() {
System.out.println("mapper constructor called"); //doesnt print
}
@Override
public Response toResponse(DataNotFoundException ex) {
System.out.println("toResponse called"); //doesnt print
ErrorMessage errorMessage = new ErrorMessage(ex.getMessage(), 404, "No documentation yet.");
return Response.status(Status.NOT_FOUND)
.entity(errorMessage)
.build();
//ErrorMessage is a simple POJO with 2 string and 1 int field
}
}
내가 자세한 정보/코드를 제공 할 수 있습니다 필요한 경우, 문제 소스입니다 확실하지 않다. 뭐가 문제 야, 내가 뭘 할 수있어?
편집 :
Main.class가 :
public class Main {
/**
* Main method.
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
...
List<ServerInfo> serverList = new ArrayList<ServerInfo>();
serverList.add(new ServerInfo(
"api",8450,
new ResourceConfig().registerClasses(
the.package.was.here.ApiResource.class)
));
for(ServerInfo server : serverList) {
server.start();
}
System.out.println("Press enter to exit...");
System.in.read();
for(ServerInfo server : serverList) {
server.stop();
}
}
}
EDIT2 : 이 this 질문에 따라 나는 단지 조금 도움이 ServerProperties.RESPONSE_SET_STATUS_OVER_SEND_ERROR, "true"
속성을 사용하여 시도했습니다. 예외가 발생하면 여전히 HTML 그리즐리 페이지가 표시되지만, 이제 페이지의 본문에 예외 (+ 스택 추적)가 표시됩니다.
매퍼가 등록되지 않은 것 같습니다. 앱 설정/구성을 표시 할 수 있습니까? –
당신은 서버를 시작하는 코드를 의미합니까? 의존성? –
적어도 ResourceConfig를 보여주는 서버 코드 –