Hello know somebody how to define a `RestTemplate...
# spring
m
Hello know somebody how to define a
RestTemplate
with the
BeanDefinitionDsl
? @sdeleuze maybe U have a sample ? 😉
Copy code
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.web.client.RestTemplate' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:798)
Copy code
Task :test

HttpsDemoClientApplicationTests > contextLoads() FAILED
    java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:132
        Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException at ConstructorResolver.java:798
            Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException at DefaultListableBeanFactory.java:1777
but when I start the applications and test it with a Rest call it woks
Copy code
@SpringBootApplication
class HttpsDemoClientApplication
fun main(args: Array<String>) {
	runApplication<HttpsDemoClientApplication>(*args){
		addInitializers(
				beans {
					bean {
						ApplicationRunner { println("-----------------> ApplicationRunner <-----------------") }
					}
//					bean<RestTemplate>(name = "restTemplate"){
//						RestTemplateBuilder().build()
//					}
//					bean {
//						RestTemplate()
//					}
					bean<RestTemplate> {
						RestTemplateBuilder().build()
					}
				}
		)
	}
}
//@Configuration
//class BeanConfiguration {
//	@Bean
//	internal fun restTemplate(restTemplateBuilder: RestTemplateBuilder) = restTemplateBuilder.build()
//}
@RestController
class CallRemoteHttpsServer (private val restTemplate: RestTemplate){
	@GetMapping
	fun sayHello() = restTemplate.getForEntity("<http://localhost:8081>", String::class.java)
}