版权声明:本文为博主原创文章,转载请标明出处 https://blog.csdn.net/qq_34299694/article/details/85155545
BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
路径配置问题:maven路径和传统开发路径的不同
一开始的路径配置
<!-- 加载spring的各种配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>spring/applicationContext-*.xml</param-value>
</context-param>
改正后的路径
<!-- 加载spring的各种配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/applicationContext-*.xml</param-value>
</context-param>
原因:传统方式下会去classes下去寻找配置中的文件,但在maven中要添加classpath:加以指认。
顺便提一下:
classpath:只会到你的class路径中查找找文件。
classpath*:不仅包含class路径,还包括jar文件中(class路径)进行查找。
注意: 用classpath*:需要遍历所有的classpath,所以加载速度是很慢的;因此,在规划的时候,应该尽可能规划好资源文件所在的路径,尽量避免使用classpath*。