问题描述
我将groovy与logback结合使用,并且在解析xml时会收到很多警告.我知道JDK1.7_u45中的错误会导致此错误.
I'm using logback with groovy and get lots of warnings showing up when parsing xml. I am aware of the bug in JDK1.7_u45 that is causing this.
Warning: org.apache.xerces.parsers.SAXParser: Property 'http://javax.xml.XMLConstants/property/accessExternalDTD' is not recognized.
Warning: org.apache.xerces.parsers.SAXParser: Property 'http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit' is not recognized.
有什么办法可以关闭此日志警告,使其不再显示在DEBUG中?我尝试使用过滤器"编写过滤器,但没有帮助.
Is there any way to turn off this log warnings from showing up in DEBUG? I tried writing a filter using Filter, but didn't help.
推荐答案
This is a known bug in the JRE that reports this as an warning. See bug reports here and here
仅当您在类路径中有xerces jar,xerces实现无法识别该属性并在 org. apache.xerces.jaxp.SAXParserImpl $ JAXPSAXParser.setProperty(),它会从 com.sun.org.apache.xalan.internal.xsltc.compiler.Parser.parse()
The issue happens only when you have xerces jar in your classpath, the xerces implementation does not recognize the property and throws an exception on org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.setProperty() which results in a warning log (to System.err) from the com.sun.org.apache.xalan.internal.xsltc.compiler.Parser.parse()
简单(如果可能)的解决方案是从类路径中删除xerces jar.
The easy (if possible) solution is remove xerces jar from your classpath.
您的日志过滤器不起作用,因为该错误永远不会发送到slf4j.哪种建议提出了解决问题的复杂方法-将 System.err重定向到slf4j ,然后在其上使用日志记录过滤器.
Your log filter does not work since the error is never sent to slf4j. Which kind of suggests a convoluted way of fixing the issue - redirect System.err to slf4j and then use a logging filter on it.
用于重现问题的示例代码(基于问题报告):
Sample code to reproduce the issue (based on the issue report):
import java.io.IOException;
import java.net.URL;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamSource;
public class XercesTest {
public static void main(String[] args) throws IOException, TransformerConfigurationException {
TransformerFactory tf = TransformerFactory.newInstance();
URL xsl = MainClass.class.getResource("build.xsl");
StreamSource stylesheetSource = new StreamSource(
xsl.openStream(), xsl.toExternalForm());
tf.newTransformer(stylesheetSource);
}
}
build.xsl
build.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<!-- TODO: Auto-generated template -->
</xsl:template>
</xsl:stylesheet>
与maven的依赖关系:
And maven dependency:
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.11.0</version>
</dependency>
这篇关于如何使用logback禁用accessExternalDTD和entityExpansionLimit警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!