Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-11351

Provide alternative RestTemplate constructor to avoid default MessageConverter creation

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 3.2.4, 4.0 GA
    • Fix Version/s: 3.2.7, 4.0.1
    • Component/s: Web:Client
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      The default MessageConverters are initialized in constructor of RestTemplate. This solution has some problems:
      1) 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.

      2) 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).

      3) 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:

      Caused by: javax.xml.transform.TransformerFactoryConfigurationError: Provider org.apache.xalan.xsltc.trax.TransformerFactoryImpl not found
      	at javax.xml.transform.TransformerFactory.newInstance(TransformerFactory.java:107)
      	at org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter.<init>(AbstractXmlHttpMessageConverter.java:47)
      	at org.springframework.http.converter.xml.SourceHttpMessageConverter.<init>(SourceHttpMessageConverter.java:47)
      	at org.springframework.web.client.RestTemplate.<init>(RestTemplate.java:154)
      

      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.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              bclozel Brian Clozel
              Reporter:
              kek Kek
              Last updater:
              Spring Issues Spring Issues
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                3 years, 37 weeks, 1 day ago