My very basic spring application stopped working and I can\'t understand what\'s happened. pom.xml:
You have to call ctx.refresh()
before you can call ctx.getBean(HelloWorld.class);
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
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