我通过APPLICATION_FORM_URLENCODED表单数据继续从任何POST操作中获取这些警告消息:
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:
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()));
}
}
因此,如果有任何表单数据,它将始终打印此警告。我做错了,因为正常操作的警告填满日志似乎不是一个好主意。
答案 0 :(得分:2)
我使用Logback和Slf4j,你只需添加" jul-to-slf4j "作为依赖项并在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 中:
<?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可以避免在日志文件中发出警告消息。