Today in writing spring program encountered a very common error, and I did not seem to have encountered before, today only to see this error, after the study to solve the error, it is really wrong to make this mistake.
Log4j:warn No Appenders could is found for logger (org.springframework.core.env.StandardEnvironment). Log4j:warn Initialize the log4j system Properly.log4j:WARN see http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info . Exception in thread "main" java.lang.IllegalStateException: beanfactory not initialized or already closed-call ' REFR Esh ' before accessing beans via the ApplicationContextat Org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory ( abstractrefreshableapplicationcontext.java:172) at Org.springframework.context.support.AbstractApplicationContext.getBean (abstractapplicationcontext.java:1097) At Com.pb.demo.Test.main (test.java:12)
Beanfactory is not instantiated or has been closed, in fact, the cause of the error is very simple, in writing:
ApplicationContext CTX = new Classpathxmlapplicationcontext ();
, when the configuration file is not specified, spring instantiates beanfactory by default to Classpath to find the file named Applicationcontext.xml, but you do not specify it, so this error occurs.
This is the reason for the error, the name of the file in parentheses to write the line.
ApplicationContext CTX = new Classpathxmlapplicationcontext ("Applicationcontext.xml");
In that case, there would be no such mistake.
Beanfactory not initialized or already closed-call ' refresh ' before accessing beans solution