-
Notifications
You must be signed in to change notification settings - Fork 41.4k
Closed
Description
Spring Boot 1.4.2
SpringBootTestContextCustomizer
defines a bean with the name testRestTemplate
that is of type TestRestTemplate
. If any user-defined bean in a unit test is defined with the same bean name, unexpected errors occur:
Such as:
java.lang.ClassCastException: org.springframework.boot.test.context.SpringBootTestContextCustomizer$TestRestTemplateFactory$$EnhancerBySpringCGLIB$$9fac7b5a cannot be cast to org.springframework.web.client.RestTemplate
Or this one (even though a RestTemplate
bean is defined) because the testRestTemplate
that was defined is of type org.springframework.boot.test.web.client.TestRestTemplate
No qualifying bean of type 'org.springframework.web.client.RestTemplate' available
Given the likelihood that someone defining a bean named testRestTemplate
in their unit test is very high, the TestRestTemplate
bean name should be namespaced (e.g. SpringBootTestContextCustomizer_testRestTemplate
) so as to not conflict with user defined beans.
Metadata
Metadata
Assignees
Labels
type: bugA general bugA general bug