Spring部署报错:Could not open ServletContext resource [/jdbc.properties]
1 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener 2 org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/jdbc:properties] 3 at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:87) 4 at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:681) 5 at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:656) 6 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:446) 7 at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385) 8 at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284) 9 at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) 10 at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4728) 11 at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5162) 12 at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 13 at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725) 14 at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701) 15 at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717) 16 at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1069) 17 at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1719) 18 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) 19 at java.util.concurrent.FutureTask.run(FutureTask.java:266) 20 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 21 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 22 at java.lang.Thread.run(Thread.java:745) 23 Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/jdbc:properties] 24 at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:140) 25 at org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(PropertiesLoaderSupport.java:181) 26 at org.springframework.core.io.support.PropertiesLoaderSupport.mergeProperties(PropertiesLoaderSupport.java:161) 27 at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:78) 28 ... 19 more
解决方法:
在spring配置中加载文件的配置修改为
<context:property-placeholder location="classpath:jdbc.properties" />