ChiManZero 2015-12-07 15:14 采纳率: 0%
浏览 1071

Exception sending context initialized event

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/src/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/src/applicationContext.xml]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:522)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1362)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1451)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:296)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1374)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1530)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1519)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/src/applicationContext.xml]
at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:140)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
... 25 more
2015-12-7 23:09:24 org.apache.catalina.core.StandardContext startInternal
严重: Error listenerStart
2015-12-7 23:09:24 org.apache.catalina.core.StandardContext startInternal
严重: Context [/userManage] startup failed due to previous errors
2015-12-7 23:09:24 org.apache.catalina.core.ApplicationContext log
信息: Closing Spring root WebApplicationContext
2015-12-7 23:09:24 org.apache.catalina.core.StandardContext listenerStop
严重: 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
at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:172)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1066)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1040)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:988)
at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:556)
at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:142)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4831)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5478)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1362)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1451)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:296)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1374)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1530)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1519)
at java.lang.Thread.run(Thread.java:662)

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-08-04 23:24
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    根据您提供的错误信息,可以确定问题出在Spring的配置文件中。XML文件中可能存在解析错误或者资源路径不正确的问题。

    以下是一些可能的原因和解决方法:

    1. 配置文件语法错误:确保您的XML文件是正确的XML文档,并且每个元素都有正确的标签。例如,检查是否使用了正确的<context-param>标签,以及它是否包含必要的属性。
    <context-param>
        <param-name>contextParamName</param-name>
        <param-value>contextParamValue</param-value>
    </context-param>
    
    1. 资源路径不正确:确认您的XML文件中的资源路径(如/src/applicationContext.xml)与实际的文件路径一致。如果路径有误,Spring容器将无法找到指定的XML文件。

    2. 解析错误:检查XML文件是否存在解析错误。这可能是由于XML格式错误、编码问题或其他原因导致的。您可以尝试使用专业的XML编辑器或工具来查看并修复这些问题。

    3. 没有初始化bean定义:如果您尝试加载一个没有被初始化的bean,那么Spring容器将会抛出异常。确保所有的bean都已经被注册到bean定义中。

    @Bean
    public MyBean myBean() {
        return new MyBean();
    }
    
    1. 错误的bean工厂实例化:如果bean定义已经存在但是没有被注入,那么Spring容器也会抛出异常。确保所有的bean都被正确地创建和注入。

    2. 级联关闭:确保Spring容器已成功初始化并且所有依赖项都已经完成。否则,Spring容器会抛出异常。

    @Autowired
    private ApplicationContext context;
    
    @Autowired
    private MyService service;
    

    对于这个特定的Exception,您可能需要提供更多的上下文信息,比如XML文件的内容,具体的错误消息等,以便于更精确地定位问题所在。

    评论

报告相同问题?