I know the error is self explanatory, but when I remove the setting of rest template from constructor to @Autowired @Qualifier("myRestTemplate") private RestTemplate restTemplate, it works.
Just want to know how can I do that in constructor if the same class has bean definition of what I am trying to autowire?
org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'xxx': Requested bean is currently in creation: Is there an unresolvable circular reference?
@Component
public class xxx {
private RestTemplate restTemplate;
@Autowired
public xxx(@Qualifier("myRestTemplate") RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}
@Bean(name="myRestTemplate")
public RestTemplate getRestTemplate() {
return new RestTemplate();
}
}
@Autowired
from you constructor. – kk.@Bean
in the same class? Could you initialize it inApplicationInitializer
(The class which is annotated as@Configuration
) class? – kk.