当前位置: 代码迷 >> 综合 >> BeanFactory not initialized or already closed - call 'refresh' before accessing beans解决办法
  详细解决方案

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

热度:46   发布时间:2023-11-24 04:36:32.0

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


BeanFactory没有实例化或者已经关闭了,其实产生错误的原因很简单,在写:
ApplicationContext ctx = new ClassPathXmlApplicationContext();
时,没有指定配置文件,Spring实例化BeanFactory的时候是默认到classPath下面查找名为applicationContext.xml的文件的,但是呢,你又没有指定,所以出现了这个错误。

最后发现问题的原因是我的resource目录下的配制文件全部没有编译过来:
在这里插入图片描述
正常情况下classes下面应该有mybatis、properties等目录和文件。但是现在没有,这就是问题的所在。 解决: 右键resources–>make dir as resource root:

  相关解决方案