We configure two separate RestTemplateBuilder beans in a java @Configuration annotated class like so:
@Bean("internal_api")
public RestTemplateBuilder internalRestTemplateBuilder(@Autowired
OAuthConsumerOperations oAuthConsumerOperations) {
...
}
@Bean("external_api")
public RestTemplateBuilder externalRestTemplateBuilder(){
...
}
When we deploy the app to Pivotal Cloud Foundry Apps Manager, we get the error below. It is complaining that more than one RestTemplateBuilder bean was found when it is expecting only one.
2018-08-28T11:59:17.67-0400 [APP/PROC/WEB/0] OUT {"timeMillis":1535471957677,"thread":"main","level":"WARN","loggerName":"org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext","message":"Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'documentationPluginsBootstrapper' defined in URL [jar:file:/home/vcap/app/BOOT-INF/lib/springfox-spring-web-2.7.0.jar!/springfox/documentation/spring/web/plugins/DocumentationPluginsBootstrapper.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMvcRequestHandlerProvider' defined in URL [jar:file:/home/vcap/app/BOOT-INF/lib/springfox-spring-web-2.7.0.jar!/springfox/documentation/spring/web/plugins/WebMvcRequestHandlerProvider.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cloudFoundryEndpointHandlerMapping' defined in class path resource [org/springframework/boot/actuate/cloudfoundry/CloudFoundryActuatorAutoConfiguration.class]: Unsatisfied dependency expressed through method 'cloudFoundryEndpointHandlerMapping' parameter 1; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.springframework.boot.web.client.RestTemplateBuilder' available: expected single matching bean but found 2: internal_api,external_api","endOfBatch":false,"loggerFqcn":"org.apache.commons.logging.impl.SLF4JLocationAwareLog","contextMap":{},"threadId":1,"threadPriority":5}
Is this a bug? Are you not all allowed to configure multiple RestTemplateBuilder beans when using spring actuator on Cloud Foundry? Is there a way around this error? If not, would creating RestTemplate beans instead of RestTemplateBuilders work? If that is the case, then does the CloudFoundryActuatorAutoConfiguration class require at least one RestTemplateBuilder bean to be defined when deployed on Cloud Foundry?