java.lang.IllegalStateException: BeanFactory not initialized or already closed

报错信息:java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext

大概看一下错误信息:BeanFactory没有实例化或者已经关闭,原因很简单:ApplicationContext ctx = new ClassPathXmlApplicationContext();Spring实例化BeanFactory的时候是默认到classPath下面查找名为applicationContext.xml的文件。但是这正是这个错误的原因:ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");如果这样的话就不会出现这样的错误了。

你可能感兴趣的:(java.lang.IllegalStateException: BeanFactory not initialized or already closed)