org.springframework.boot.test.web.client

Class TestRestTemplate



  • public class TestRestTemplate
    extends Object
    Convenient alternative of RestTemplate that is suitable for integration tests. They are fault tolerant, and optionally can carry Basic authentication headers. If Apache Http Client 4.3.2 or better is available (recommended) it will be used as the client, and by default configured to ignore cookies and redirects.

    Note: To prevent injection problems this class intentionally does not extend RestTemplate. If you need access to the underlying RestTemplate use getRestTemplate().

    If you are using the @SpringBootTest annotation, a TestRestTemplate is automatically available and can be @Autowired into your test. If you need customizations (for example to adding additional message converters) use a RestTemplateBuilder @Bean.

    Since:
    1.4.0
    Author:
    Dave Syer, Phillip Webb, Andy Wilkinson, Kristine Jetzke