請解釋在使用工廠的以下場景中使用Google-Guice自動連線的正確方法。我正在使用XML工廠進行XSLT處理。Google Guice爲工廠自動裝配
StringWriter strWriter = new StringWriter();
System.setProperty("javax.xml.transform.TransformerFactory",
"net.sf.saxon.TransformerFactoryImpl");
TransformerFactory xmlTransformerFactory = TransformerFactory.newInstance();
CustomUriResolver out = new CustomUriResolver(new HashMap<String, StringWriter>());
xmlTransformerFactory.setAttribute("http://saxon.sf.net/feature/outputURIResolver", out);
Transformer xmlTransfomer = xmlTransformerFactory.newTransformer(new StreamSource("src/main/resources/test.xslt"));
xmlTransfomer.transform(new StreamSource(new StringReader(xml)), new StreamResult(strWriter));
System.out.println(out.getResults().size());
for(Map.Entry resultEntry : out.getResults().entrySet()){
System.out.println(resultEntry.getValue());
};
我應該有自動線變壓器廠,這需要定製URI resolver.Also這段代碼是API將繼續接受請求並處理它。但是那麼它必須調用newTransformer的一部分()爲它收到的每一個請求。
你需要一個新的變壓器每次還是要變壓器可用通過吉斯在整個應用程序中的單身? – pandaadb
我需要它作爲單身..我可以使用相同的實例所有請求 –