使用Spring出现的错误: BeanFactory not initialized or already closed - call 'refresh' before accessin

使用Spring出现如下错误:

严重: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext

 

只要出现如下的错误一定是和ApplicationContext.xml(Spring的配置文件)有关的,就是其获取其配置文件出了问题。

  • 1.使用此种方法可能是其配置文件名拼写错误或是没写。也就是ApplicationContext.xml(当然你也可以起其他名字)
ApplicationContext ac = new ClassPathXmlApplicationContext("ApplicationContext.xml");
  • 2.让tomcat在启动时,直接通过web.xml加载ApplicationContext.xml,查看自己配的web.xml是否正确?我就是这里错误。


  
	
		contextConfigLocation
		
		classpath:AirportServlet
	
	
	
	
		org.springframework.web.context.ContextLoaderListener
	

 

你可能感兴趣的:(javaEE基础学习,Java学习)