mso*_*ori 29 java groovy logback saxparser xerces2-j
我正在使用groovy的logback并在解析xml时出现很多警告.我知道JDK1.7_u45中导致此问题的错误.
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.
Run Code Online (Sandbox Code Playgroud)
有没有办法关闭这个日志警告出现在DEBUG?我尝试使用Filter编写过滤器,但没有帮助.
6to*_*ton 21
这是JRE中的一个已知错误,它将此报告为警告.请参阅此处和此处的错误报告
只有在类路径中有xerces jar时才会出现问题,xerces实现无法识别该属性并在org.apache.xerces.jaxp.SAXParserImpl $ JAXPSAXParser.setProperty()上抛出异常,从而导致出现警告日志(发送到系统.err)来自com.sun.org.apache.xalan.internal.xsltc.compiler.Parser.parse()
简单(如果可能)解决方案是从类路径中删除xerces jar.
您的日志过滤器不起作用,因为错误永远不会发送到slf4j.哪种方式表明解决问题的复杂方法 - 将System.err重定向到slf4j,然后对其使用日志记录过滤器.
用于重现问题的示例代码(基于问题报告):
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);
}
}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
和maven依赖:
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.11.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
29810 次 |
| 最近记录: |