AnnotationConfigApplicationContext has not yet been updated - what happened?

My very basic spring application has stopped working and I cannot figure out what happened. pom.xml:

<properties> <spring.version>4.1.1.RELEASE</spring.version> </properties> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> </dependencies> 

Configuration class:

 @Configuration public class MyConfig { @Bean public HelloWorld helloWorld() { return new HelloWorld(); } } 

Bean class:

 public class HelloWorld { private String message; public void setMessage(String message) { this.message = message; } public String getMessage() { return message; } } 

Application Entry Point:

 public class MainApp { public static void main(String[] args) { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(MyConfig.class); HelloWorld bean = ctx.getBean(HelloWorld.class); bean.setMessage("ladjfaj"); System.out.println(bean.getMessage()); } } 

And I get an error

An exception was thrown in the main thread java.lang.IllegalStateException: org.spring framework.context.annotation.AnnotationConfigApplicationContext@ 6ebf8cf5 has not yet been updated in org.springframework.context.support.AbstractApplicationContext.assertBeanFactoryActive (AbstractApplicationContext.java:943) in org.spring.source .AbstractApplicationContext.getBean (AbstractApplicationContext.java:967) at com.nikolas.config.MainApp.main (MainApp.java:12)

+7
java spring configuration
source share
1 answer

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

+13
source share

All Articles