Make TestRestTemplate not extend RestTemplate
Update TestRestTemplate so that it no longer directly extends RestTemplate. Prior to this commit it was possible that TestRestTemplate could interfere with user defined RestTemplate beans. TestRestTemplate offers the same methods as RestTemplate so should be a drop-in replacement. If access is needed to the actual underlying template the `getRestTemplate()` method should be used. Fixes gh-5915
This commit is contained in:
@@ -35,7 +35,6 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -66,7 +65,7 @@ public class SampleTomcatApplicationTests {
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
requestHeaders.set("Accept-Encoding", "gzip");
|
||||
HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders);
|
||||
RestTemplate restTemplate = new TestRestTemplate();
|
||||
TestRestTemplate restTemplate = new TestRestTemplate();
|
||||
ResponseEntity<byte[]> entity = restTemplate.exchange(
|
||||
"http://localhost:" + this.port, HttpMethod.GET, requestEntity,
|
||||
byte[].class);
|
||||
|
||||
Reference in New Issue
Block a user