Provide alternative RestTemplate constructor to avoid default MessageConverter creation [SPR-11351] #15976
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
status: backported
An issue that has been backported to maintenance branches
type: enhancement
A general enhancement
Milestone
Kek opened SPR-11351 and commented
The default MessageConverters are initialized in constructor of RestTemplate. This solution has some problems:
When I want different set of MessageConverters, the default MessageConverters are initialized first and than replaced by setMessageConverters(..) method. This slows down the application startup.
When I have some classes as JAXB, Jackson on classpath, than some other default converters are initialized too (but I don't use these technologies (JAXB, Jackson) with RestTempate) - this slows down the startup, so I want to specify my "limited" set of Converters - but is the same problem as 1).
When I have 2 WAR applications in Tomcat, and one application sets the System property "javax.xml.transform.TransformerFactory" for Xalan XSLTC, and the second application does not have Xalan on classpath and does not use the XSLT,but instantiates RestTemplate for JSON based communication, than Exception is thrown:
I don´t want to initialize any default XML message Converter for RestTemplate, because I use only JSON for communication -> I want to configure my own set of MessageConverters, but the constructor is called first and destroyed by the exception.
So please, move the initialization of default MessageConvertors for RestTemplate from constructor to some
@PostConstruct
method, and initialize these default converters only in situations, when the Array of converters was not set (preinitialized) by setMessageConventers(...) operation from configuration.Affects: 3.2.4, 4.0 GA
Issue Links:
Referenced from: commits 1cb9b9c, 425e5a0
Backported to: 3.2.7
0 votes, 8 watchers
The text was updated successfully, but these errors were encountered: