来自 Jersey 2.x 的过多警告消息消息、Jersey

由网友(群众逗比)分享简介:我不断从任何带有 APPLICATION_FORM_URLENCODED 表单数据的 POST 操作中收到这些警告消息:I keep getting these warning messages from any POST operation with APPLICATION_FORM_URLENCODED form...

我不断从任何带有 APPLICATION_FORM_URLENCODED 表单数据的 POST 操作中收到这些警告消息:

I keep getting these warning messages from any POST operation with APPLICATION_FORM_URLENCODED form data:

A servlet request to the URI (local request URI) contains form parameters in the request body   but the request body has been consumed by the servlet or a servlet filter accessing the request parameters. Only resource methods using @FormParam will work as expected. Resource methods consuming the request body by other means will not work as expected.

我已将其追溯到 org.glassfish.jersey.servlet.WebComponent:

I've traced this down to org.glassfish.jersey.servlet.WebComponent:

        if (!form.asMap().isEmpty()) {
            containerRequest.setProperty(InternalServerProperties.FORM_DECODED_PROPERTY, form);

            if (LOGGER.isLoggable(Level.WARNING)) {
                LOGGER.log(Level.WARNING, LocalizationMessages.FORM_PARAM_CONSUMED(containerRequest.getRequestUri()));
            }
        }

所以,如果有任何表单数据,它总是会打印这个警告.我是否做错了什么,因为用正常操作的警告填充日志似乎不是一个好主意.

So, if there's any form data, it will always print this warning. Am I doing something wrong as filling up the log with warnings for normal operations doesn't seem like a good idea.

推荐答案

我正在使用 Logback 和 Slf4j,你只需添加jul-to-slf4j"作为依赖项并配置它logback.xml.

I'm using Logback with Slf4j, and you only should add "jul-to-slf4j" as dependency and configure it in logback.xml.

在 pom.xml 中:

<dependency>
      <groupId>ch.qos.logback</groupId>  
      <artifactId>logback-classic</artifactId>
      <version>${logback.version}</version>
 </dependency>
 <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>${slf4j.version}</version>
 </dependency>
 <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>jul-to-slf4j</artifactId>
      <version>${slf4j.version}</version>
 </dependency>

要将 jul 消息重定向到 logback,请在 logback.xml 中添加以下内容:

To redirect jul messages to logback, add this inside in logback.xml:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
        <resetJUL>true</resetJUL>
    </contextListener>

    <appender name="OUT" class="ch.qos.logback.core.ConsoleAppender">
    ...

    <logger name="org.glassfish.jersey.servlet" level="ERROR" />

</configuration>

将 org.glassfish.jersey.servlet 的级别设置为 ERROR 可以避免日志文件中出现警告消息.

Setting level for org.glassfish.jersey.servlet to ERROR lets you avoid warning messages in log files.

阅读全文

相关推荐

最新文章