TestRestTemplate replaces custom HttpClients
See original GitHub issueSpring-Boot version 1.5.2.RELEASE
Problem: When apache httpclient jar is in the classpath, TestRestTemplate replaces any HttpClient set by the user in a RestTemplate. Alseo, since the field is final there’s no way to change that, even with reflection. See this https://github.com/spring-projects/spring-boot/blob/master/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java#L127-L130.
In my case, I am building a client for mutual authentication and some headers. However, the same applications uses httpclient for other integrations, not only that, previous tests were written in RestAssured which also includes that dependency.
Is it possible to remove that validation, make it optional or just apply it if there’s no requestFactory set?
Issue Analytics
- State:
- Created 6 years ago
- Comments:13 (9 by maintainers)

Top Related StackOverflow Question
@bvulaj Unfortunately we needed to introduce a breaking change so 2.0 was the only option.
@philwebb Understood. Will use the workaround for now. Thanks for the response.