在ssh中 无法读取数据源配置文件 dataSource.properties 的问题
来源:互联网 发布:手机usb共享网络打不开 编辑:程序博客网 时间:2024/05/21 19:38
- 错误
十月 11, 2016 5:32:41 下午 org.apache.catalina.core.ApplicationContext log信息: Initializing Spring root WebApplicationContext十月 11, 2016 5:32:42 下午 org.apache.catalina.core.StandardContext listenerStart严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListenerorg.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/dataSource.properties]at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.postProcessBeanFactory(PropertySourcesPlaceholderConfigurer.java:151)at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:265)at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:162)at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606)at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462)at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1551)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:497)at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:622)at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:569)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:497)at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1466)at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1307)at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1399)at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:828)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:497)at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:323)at sun.rmi.transport.Transport$1.run(Transport.java:200)at sun.rmi.transport.Transport$1.run(Transport.java:197)at java.security.AccessController.doPrivileged(Native Method)at sun.rmi.transport.Transport.serviceCall(Transport.java:196)at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$254(TCPTransport.java:683)at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$1/444230198.run(Unknown Source)at java.security.AccessController.doPrivileged(Native Method)at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)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: Could not open ServletContext resource [/dataSource.properties]at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:117)at org.springframework.core.io.support.EncodedResource.getInputStream(EncodedResource.java:143)at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:98)at org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(PropertiesLoaderSupport.java:175)at org.springframework.core.io.support.PropertiesLoaderSupport.mergeProperties(PropertiesLoaderSupport.java:156)at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.postProcessBeanFactory(PropertySourcesPlaceholderConfigurer.java:142)... 53 more十月 11, 2016 5:32:42 下午 org.apache.catalina.core.ApplicationContext log信息: Closing Spring root WebApplicationContext<span style="font-size:14px;"> </span>
- 分析原因
单纯代码测试中 这个问题不会出现 一旦部署到容器中 就会抛出上面的异常
因为 在 web.xml文件中 我们要在应用启动就加载 spring的配置文件 所以会在web.xml中 配置相关信息如下
<!--应用启动就加载配置文件--> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:spring_cfg.xml</param-value> </context-param>
这样 可以在加载时 就读取spring的配置文件 当读到 dataSource.properties时 我们很容易在spring中的配置文件中 进行如下的错误配置
<!--加载数据源配置文件 此处要解决路径问题 避免部署时出现问题--> <context:property-placeholder location="dataSource.properties"/>
这时 io无法正确加载 dataSource.properties 归根到底就是路径问题
所以 如法炮制 在 dataSource.properties 前也加上 classpath*:
正确的方式为:<!--加载数据源配置文件 此处要解决路径问题 避免部署时出现问题--> <context:property-placeholder location="classpath:dataSource.properties"/>
0 0
- 在ssh中 无法读取数据源配置文件 dataSource.properties 的问题
- 简单读取dataSource.properties配置文件
- 有关配置文件 properties无法读取问题
- 读取配置文件properties的问题
- spring 配置文件中datasource 从properties文件中获取mysql数据库连接参数遇到的问题
- springmvc通过@Value注解读取Properties配置文件的值,junit测试可以取到值,但是在业务中无法读取
- 如何在spring中读取properties配置文件里面的信息
- 如何在spring中读取properties配置文件里面的信息
- 如何在spring中读取properties配置文件里面的信息
- 在spring中读取properties配置文件里面的信息
- 如何在spring中读取properties配置文件里面的信息
- 如何在spring中读取properties配置文件里面的信息
- 配置文件中如何读取properties的配置文件
- JDBC中关于封装和读取配置文件properties的问题
- 在spring中读取properties配置文件
- 在配置文件中读取:jdbc.properties文件
- Spring配置文件中配置数据源(dataSource)
- Spring配置文件所有类型的数据源dataSource
- windows 自动备份mysql方案
- python SimpleHTTPServer 快速搭建Web服务器
- JVM实用参数(七)CMS收集器
- MongoDb-CRUD
- MATLAB linspace创建向量
- 在ssh中 无法读取数据源配置文件 dataSource.properties 的问题
- PHP中(&& ||)的简洁写法
- 子程序与变量
- Hdu 2243 考研路茫茫——单词情结
- JSP中调用ajax执行post请求不成功
- android activty 伪弹框学习笔记
- 基于GIS的定位监控系统开发教程-关于本教程
- 通过非聚集索引让select count(*) from 的查询速度提高几十倍、甚至千倍
- DefaultMQProducer.send(message, timeout)的消息发送状态sendResult.getSendStatus()不可用性