AnnotationConfigApplicationContext has not been refreshed yet - what's wrong?

前端 未结 3 1682
独厮守ぢ
独厮守ぢ 2021-01-07 19:15

My very basic spring application stopped working and I can\'t understand what\'s happened. pom.xml:


    

        
相关标签:
3条回答
  • 2021-01-07 19:45

    You have to call ctx.refresh() before you can call ctx.getBean(HelloWorld.class);

    0 讨论(0)
  • 2021-01-07 19:49

    Just in case someone has a similar issue and can´t relate directly to the example above, this may help:

    I ran into the problem when I had one of my repositories outside of the folder that was included in

    @EnableJpaRepositories(basePackages = {"com.myproject.repositores"})
    

    Which lead to this first exception:

    Description: Field profileRepository in com.myproject.featurepackage.config.ProfileService required a bean of type 'com.myproject.featurepackage.ProfileRepository' that could not be found. The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true)

    When I afterwards accessed the ApplicationContext to instanciate a bean, I ran into the error

    org.springframework.context.annotation.AnnotationConfigApplicationContext@4983159f has not been refreshed yet

    0 讨论(0)
  • 2021-01-07 20:02

    If you dont want to call ctx.refresh() explicitly, just initialize ApplicationContext like this: new AnnotationConfigApplicationContext(MyConfig.class), then configuration will be registered and refreshed implicitly

    0 讨论(0)
提交回复
热议问题