今天,在搭建一个商城项目的过程中,遇到了这么一个问题java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
我是在service层启动的tomcat插件,由于习惯性的在web.xml文件中初始化spring容器,如下
<!-- 初始化spring容器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/applicationContext-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
导致在tomcat启动的时候在classpath路径下找不到applicationContext_*.xml文件,(因为我还没有applicationContext_*.xml文件)导致报错。这算是一个很低级的错误,对于搭建环境来说,还是每一步用到的时候再增加,一步一步去搭建。对于高手来说,可以略过^^