本文介绍了grizzly不会在请求中记录异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经设置了这样一个简单的球衣服务器:
I've set up a simple jersey server like this:
ResourceConfig rc = new ResourceConfig().packages("com.example.jersey_test/services");
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(URI.create(API_URI), rc);
我有一个简单抛出异常的bean:
And I have a bean that simply throws an exception:
@Path("persons")
public class PersonService {
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getPersons() {
java.util.logging.Logger.getGlobal().log(Level.INFO, "test");
throw new RuntimeException("test");
}
}
日志输出如下(所以日志记录有效,但未记录异常):
The log output is the following (so logging works, but the exception is not logged):
Jul 01, 2014 10:19:33 PM com.example.jersey_test.services.PersonService getPersons
INFO: test
响应是500,看起来如下(所以堆栈跟踪不包括在内):
The response is a 500 with looks like the following (so the stacktrace is not included):
,灰熊应该使用默认的日志记录API。我做错了什么?
As this answer states, grizzly should be using the default logging API. What am I doing wrong?
推荐答案
有一种方法可以启动一个灰熊服务器,它既记录又打印出响应中的异常:
There is a way to start a grizzly server that both logs and prints out exceptions in the response:
HttpServer server =
GrizzlyWebContainerFactory.create(getBaseURI(),
Collections.singletonMap("javax.ws.rs.Application",
"class.that.extends.ResourceConfig"));
这篇关于grizzly不会在请求中记录异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!