天天看点

BeanFactory not initialized or already closed - call 'refresh' before accessing beans解决办法

BeanFactory not initialized or already closed - call 'refresh' before accessing beans解决办法

BeanFactory没有实例化或者已经关闭了,其实产生错误的原因很简单,在写:

ApplicationContext ctx = new ClassPathXmlApplicationContext();

时,没有指定配置文件,Spring实例化BeanFactory的时候是默认到classPath下面查找名为applicationContext.xml的文件的,但是呢,你又没有指定,所以出现了这个错误。

最后发现问题的原因是我的resource目录下的配制文件全部没有编译过来:

BeanFactory not initialized or already closed - call 'refresh' before accessing beans解决办法

正常情况下classes下面应该有mybatis、properties等目录和文件。但是现在没有,这就是问题的所在。 解决: 右键resources–>make dir as resource root:

继续阅读