泽西岛2.0和Moxy内部服务器错误,但没有服务器日志 [英] Jersey 2.0 and Moxy Internal Server Error But No Server Log

查看:77
本文介绍了泽西岛2.0和Moxy内部服务器错误,但没有服务器日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了Jersey 2.0文档( https://jersey.java.net/documentation/latest/user-guide.html#json.moxy ),修改后的pom.xml,包括jersey-media-moxy构件,已编译并安装.对于Produce和Consume案例,我都可以获得从POJO到JSON的基本映射工作.

I followed the Jersey 2.0 document (https://jersey.java.net/documentation/latest/user-guide.html#json.moxy), modified pom.xml, included jersey-media-moxy artifact, compiled and installed. I could get basic POJO to JSON mapping work for both Produces and Consumes cases.

但是,当我尝试使用一些具有复杂数据类型的POJO作为资源返回类型时,出现了很多Status 500 Internal Server Error,但没有任何服务器日志.这很烦人.有人知道这是一个错误还是我错过了配置中的某些内容?

However, when I tried with some POJO with complex data type as resource return type, I got a lot Status 500 Internal Server Error but without any server log. It is very annoying. Does anybody know if it is a bug or I missed something in configuration?

顺便说一句,为了对POJO对象使用Moxy映射,POJO需要有一个空的参数构造函数.还有其他要求吗?

By the way, in order to use Moxy mapping for a POJO object, the POJO needs to have a empty parameter constructor. Are there any other requirements?

推荐答案

我遇到了同样的问题,并发现了这篇文章:

I had the same problem and found this post:

作者实现了ApplicationEventListener来记录Moxy抛出的异常.这是我的实现(需要在您的应用程序中注册):

The author implemented ApplicationEventListener to log the exceptions thrown by Moxy. This is my implementation (needs to be registered in your application):

public class ExceptionListener implements ApplicationEventListener {

    @Override
    public void onEvent(ApplicationEvent event) {

    }

    @Override
    public RequestEventListener onRequest(RequestEvent requestEvent) {
        return new ExceptionRequestEventListener();
    }

    public static class ExceptionRequestEventListener implements RequestEventListener{
        private final Logger logger;

        public ExceptionRequestEventListener(){
            logger = Logger.getLogger(getClass());
        }

        @Override
        public void onEvent(RequestEvent event) {
            switch (event.getType()){
                case ON_EXCEPTION:
                    Throwable t = event.getException();
                    logger.error("Found exception for requestType: "+event.getType(), t);
            }
        }
    }
}

这篇关于泽西岛2.0和Moxy内部服务器错误,但没有服务器日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆