エラーは自明ですが、コンストラクタから@Autowired @Qualifier( "myRestTemplate")への残りのテンプレートの設定を削除すると、 )private RestTemplate restTemplate、それは動作します。同じクラスのBean作成によるSpring Autowireの結果:リクエストされたBeanが現在作成中Error *
同じクラスに私がautowireしようとしているもののbean定義がある場合、コンストラクタでそれをどうやって行うことができますか?
org.springframework.beans.factory.BeanCurrentlyInCreationException: エラーが 'XXX' の名前を持つBeanを作成:要求Beanが 作成中です:解決できない循環参照がありますか?定期
@Component
注釈付きクラスの
@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'を削除してください。 –
@KrishnaKuntala私はデフォルトコンストラクタを持っていないので動作しませんので、このコンストラクタでAutowiredが必要です。 – Abhijeet
あなたのポイントを得ました。なぜあなたは '@ Bean'を同じクラスに作成したいのですか? 'ApplicationInitializer'(' @ Configuration'という名前のクラス)クラスで初期化できますか? –