2017-07-16 136 views
0

我开发了一个简单的Spring-Hibernate Web应用程序。当我启动这个应用程序时,tomcat控制台报告下面的错误。由于此错误,应用程序无法处理任何弹簧请求。Spring-hibernate应用程序启动失败 - jpaContext.xml文件丢失

INFO: Loading XML bean definitions from class path resource [jpaContext.xml] 
Jul 16, 2017 4:41:56 PM org.springframework.web.context.ContextLoader initWebApplicationContext 
SEVERE: Context initialization failed 
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [jpaContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [jpaContext.xml] cannot be opened because it does not exist 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303) 
    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:130) 
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:539) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451) 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4853) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5314) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 
Caused by: java.io.FileNotFoundException: class path resource [jpaContext.xml] cannot be opened because it does not exist 
    at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:171) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:329) 
    ... 21 more 

Jul 16, 2017 4:41:56 PM org.apache.catalina.core.StandardContext listenerStart 
SEVERE: 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 class path resource [jpaContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [jpaContext.xml] cannot be opened because it does not exist 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303) 
    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:130) 
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:539) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451) 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4853) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5314) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 
Caused by: java.io.FileNotFoundException: class path resource [jpaContext.xml] cannot be opened because it does not exist 
    at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:171) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:329) 
    ... 21 more 

Jul 16, 2017 4:41:56 PM org.apache.catalina.core.StandardContext startInternal 
SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file 
Jul 16, 2017 4:41:56 PM org.apache.catalina.core.StandardContext startInternal 
SEVERE: Context [/LibraryApp] startup failed due to previous errors 
Jul 16, 2017 4:41:56 PM org.apache.catalina.core.ApplicationContext log 
INFO: Closing Spring root WebApplicationContext 
Jul 16, 2017 4:41:56 PM org.springframework.web.context.support.XmlWebApplicationContext doClose 
INFO: Closing Root WebApplicationContext: startup date [Sun Jul 16 16:41:56 IST 2017]; root of context hierarchy 
Jul 16, 2017 4:41:56 PM org.springframework.web.context.support.XmlWebApplicationContext doClose 
WARNING: Exception thrown from ApplicationListener handling ContextClosedEvent 
java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: Root WebApplicationContext: startup date [Sun Jul 16 16:41:56 IST 2017]; root of context hierarchy 
    at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:347) 
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:334) 
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1051) 
    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1012) 
    at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:586) 
    at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:143) 
    at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4900) 
    at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5537) 
    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:221) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:149) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 

Jul 16, 2017 4:41:56 PM org.springframework.web.context.support.XmlWebApplicationContext doClose 
WARNING: Exception thrown from LifecycleProcessor on context close 
java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: Root WebApplicationContext: startup date [Sun Jul 16 16:41:56 IST 2017]; root of context hierarchy 
    at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:360) 
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1059) 
    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1012) 
    at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:586) 
    at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:143) 
    at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4900) 
    at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5537) 
    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:221) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:149) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 

Jul 16, 2017 4:41:56 PM org.apache.catalina.core.StandardContext listenerStop 
SEVERE: 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:171) 
    at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1092) 
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1066) 
    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1012) 
    at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:586) 
    at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:143) 
    at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4900) 
    at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5537) 
    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:221) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:149) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 
+0

你应该提供更多的信息。 – onetwo12

+0

@ onetwo12但哪些信息?这可能是一个新用户,让我们引导他们开悟。 –

+0

你需要什么信息?以下是我认为应该有用的一些。不能复制POM.xml的内容 - Spring版本4.1.0.RELEASE,hibernate核心3.3.2ga,hibernate注释3.4.0 ga,hibernate实体管理器3.4.0 ga。 –

回答

0
I could able to resolve this issue by following way. I was using Servlet 3.0 specification to provide deployment descriptor using Java class. This java class implements *AbstractAnnotationConfigDispatcherServletInitializer* and overrides below methods. 

@Override`enter code here 
     protected Class<?>[] getRootConfigClasses() { 
      return new Class<?>[0]; 
// above line used to be- return new Class<?>[] { RootConfig.class }; 
     } 

     @Override 
     protected Class<?>[] getServletConfigClasses() { 
      return new Class<?>[]{ WebConfig.class }; 
     } 

     @Override 
     protected String[] getServletMappings() { 
      return new String[]{ "/web/*" }; 
     } 

basically I return a array of zero size from getRootConfigClasses method which disable the loading of ContextLoadListener. This listener used to load other configuration files like Spring bean configuration, JPA context in case there is any, which i was not providing in earlier case when I was returning an array of one class.