泽西岛:什么“找不到语法元素”意思? [英] Jersey: what does "couldn't find grammar element" mean?

查看:103
本文介绍了泽西岛:什么“找不到语法元素”意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将Jersey从版本1.15升级到1.17后,它开始记录以下消息:

After upgrading Jersey from version 1.15 to 1.17 it started to log the following messages:

Apr 2, 2013 5:13:06 PM com.sun.jersey.server.wadl.generators.AbstractWadlGeneratorGrammarGenerator attachTypes
INFO: Couldn't find grammar element for class java.lang.String

产生此类消息的服务示例:

An example of a service that produces such a message:

@GET
@Path("/bla/{a}")
@Produces("application/json")
public String doStuff(@PathParam("a") String a) {
    return a;
}

我的第一印象是将此视为错误消息,纯粹基于消息的措辞方式(找不到)。但是,它记录在INFO级别,并且它似乎在实践中没有任何影响,因为所有服务都继续工作。

My first impression would be to consider this an error message, purely based on the way the message is phrased ("couldn't find"). However, it's logged at a level of INFO, and it doesn't seem to have any effects in practice since all services continue to work.

所以我的问题是这些日志消息是否表明我们配置或使用Jersey的方式存在(潜在)问题。由于以前的版本没有发生,我已经检查了发行说明,但没有发现任何相关内容。

So my question is whether these log messages indicate a (potential) problem with the way we are configuring or using Jersey. Since it didn't happen with the previous version I already checked the release notes, but didn't find anything related.

推荐答案

我也有同样的信息消息。我没有设法修复它(还)基本的java类型(Boolean,String ...)但是对于我自己的自定义类,如果我添加@XmlRootElement注释和默认的no-param构造函数,消息就会消失。

I had the same "info" message as well. I didn't manage to fix it (yet) for basic java types (Boolean, String...) but for my own custom classes if I add the @XmlRootElement annotation and a default no-param constructor the message dissapears.

挖掘泽西源代码我注意到类WadlGeneratorJAXBGrammarGenerator以下代码:

Digging into jersey source code I noticed the class "WadlGeneratorJAXBGrammarGenerator" the following code :

Object parameterClassInstance = null;
try {
    Constructor<?> defaultConstructor = type.getDeclaredConstructor();
    defaultConstructor.setAccessible(true);
    parameterClassInstance = defaultConstructor.newInstance();
} catch (InstantiationException ex) {
    LOGGER.log(Level.FINE, null, ex);
} catch (IllegalAccessException ex) {
    LOGGER.log(Level.FINE, null, ex);
} catch (IllegalArgumentException ex) {
    LOGGER.log(Level.FINE, null, ex);
} catch (InvocationTargetException ex) {
    LOGGER.log(Level.FINE, null, ex);
} catch (SecurityException ex) {
    LOGGER.log(Level.FINE, null, ex);
} catch (NoSuchMethodException ex) {
    //getting here for Boolean/String and some other primitive data type
    LOGGER.log(Level.FINE, null, ex);
}

if (parameterClassInstance==null) {
    return null;
}

所以基本上没有String,Boolean和其他一些的默认构造函数那么它抛出一个NoSuchMethodException,因此它返回空值并记录信息消息。

So basically there is no default constructor for String, Boolean and few others then it throws a NoSuchMethodException therefore it return nulls and log the info message.

所以仍然不知道为什么会发生但是在我的情况下解决方案是禁用wadl生成,因为我是不使用它。
只需将以下参数添加到您的web.xml

So still no idea why it happens but in my case the solution was to disable the wadl generation since I was not using it. Just add the following param to your web.xml

  <init-param>
         <param-name>com.sun.jersey.config.feature.DisableWADL</param-name>
         <param-value>true</param-value>
     </init-param>

这篇关于泽西岛:什么“找不到语法元素”意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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