Requested bean is currently in creation: Is there an unresolvable circular reference?

后端 未结 7 835
夕颜
夕颜 2020-12-08 01:48

i am using spring 3, and i have two beans of view scope:

1- Bean1:

@Component(\"bean1\")
@Scope(\"view\")
public class Bean1 {

@Aut         


        
7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-08 02:33

    In my case, I was defining a bean and autowiring it in the constructor of the same class file.

    @SpringBootApplication
    public class MyApplication {
        private MyBean myBean;
    
        public MyApplication(MyBean myBean) {
            this.myBean = myBean;
        }
    
        @Bean
        public MyBean myBean() {
            return new MyBean();
        }
    }
    

    My solution was to move the bean definition to another class file.

    @Configuration
    public CustomConfig {
        @Bean
        public MyBean myBean() {
            return new MyBean();
        }
    }
    

提交回复
热议问题