Home  >  Forum  >  Spring
Post New Query

Error call 'refresh' before accessing beans via the ApplicationContext


joined on
December 28,2013
Asked on August 09,2014
Hi, I am using 
  
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();  
ctx.register(Configuration.class);

But got below error. What is wrong?


Caused by: java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:170)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:985)
at com.concretepage.WebAppInitializer.onStartup(WebAppInitializer.java:17)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5423)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 10 more

joined on
October 10,2013
Replied on August 09,2014

You should use
ctx.refresh();
as

ctx.setServletContext(servletContext);
ctx.refresh();


It will remove your error.

Write Answer








Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us