在本文(https://www.ahoi-it.de/ahoi/news/java-xslt-memory-leak/4830)中,解释了Javax xml转换器将XML内容缓存到其内部HashMap中以供以后使用。
这是我的问题:我正在从activemq读取XML消息,如果出现故障,我将尝试再次使用Javax XML转换器将其转换并将其发送到特定端点。问题在于,最终我的Docker容器会因为内存不足而重新启动。
不幸的是,我想做的是禁用缓存,经过3个小时的研究,我仍然不知道该怎么做。
我有一个带有静态方法的utils类,这就是我的Javax XML Transformer的样子:
public static String getTransformedXml(Object input, String transformerFileName)
throws IOException, TransformerException {
ClassPathResource classPathResource = new ClassPathResource(transformerFileName);
InputStream xsltStream = classPathResource.getInputStream();
TransformerFactory factory = TransformerFactory.newInstance();
Source xslt = new StreamSource(xsltStream);
Transformer transformer = factory.newTransformer(xslt);
transformer.setErrorListener(new XsltTransformerErrorListener(transformerFileName));
Source text = new StreamSource(new StringReader(XmlUtils.encode(input, input.getClass())));
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
transformer.transform(text, result);
return result.getWriter().toString();
}