class path resource cannot be opened because it does not exits
来源:互联网 发布:东方卫视网络电视台 编辑:程序博客网 时间:2024/06/07 16:30
E:\SoftwareTools\Java\jdk\bin\java ...八月 12, 2017 10:42:56 下午 org.springframework.context.annotation.AnnotationConfigApplicationContext prepareRefresh信息: Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@3f91beef: startup date [Sat Aug 12 22:42:56 CST 2017]; root of context hierarchy八月 12, 2017 10:42:57 下午 org.springframework.context.annotation.AnnotationConfigApplicationContext refresh警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.yubai.EL.ELConfig]; nested exception is java.io.FileNotFoundException: class path resource [com/yubai/EL/test.properties] cannot be opened because it does not existException in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.yubai.EL.ELConfig]; nested exception is java.io.FileNotFoundException: class path resource [com/yubai/EL/test.properties] cannot be opened because it does not exist at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:181) at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:308) at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:228) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:270) at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525) at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:84) at com.yubai.EL.MainEl.main(MainEl.java:7)
分析思路
在路劲com/yubai/EL下存在此文件,但错误信息输出如下:
class path resource [com/yubai/EL/test.properties] cannot be opened because it does not exist
从错误信息可以看出
1. com/yubai/EL/test.properties 这个文件不存在,但从图片中可以看出,此文件是存在的,可想而知,IDEA不是在此文件下查找的,所以test.properties不应该放在此目录下。
2. 再查看错误信息,可以看出class path resource ,是在resource文件下查找的,在此resource文件夹下没有com/yubai/EL/test.properties,所以当我尝试在resource下创建此目录与文件后(com/yubai/EL/test.properties),再次执行就可以运行了
代码块
package com.yubai.EL;import org.apache.commons.io.IOUtils;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.annotation.Value;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.context.annotation.PropertySource;import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;import org.springframework.core.env.Environment;import org.springframework.core.io.Resource;@Configuration@PropertySource("classpath:com/yubai/EL/test.properties")public class ELConfig { @Value("classpath:com/yubai/EL/test.txt") private Resource testFile; @Value("${book.name}") private String bookName; @Bean public static PropertySourcesPlaceholderConfigurer propertyConfigurer(){ return new PropertySourcesPlaceholderConfigurer(); } public void output(){ try{ System.out.println(bookName); System.out.println(IOUtils.toString(testFile.getInputStream())); }catch (Exception e){ e.printStackTrace(); } }}
Main.java
package com.yubai.EL;import org.springframework.context.annotation.AnnotationConfigApplicationContext;public class MainEl { public static void main(String[] args) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ELConfig.class); ELConfig resource = context.getBean(ELConfig.class); resource.output(); context.close(); }}
阅读全文
0 0
- class path resource cannot be opened because it does not exits
- java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not
- java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not
- 关于class path resource [applicationContext.xml] cannot be opened because it does not exist
- java.io.FileNotFoundException: class path resource [bean.xml] cannot be opened because it does not e
- java.io.FileNotFoundException: class path resource [spring.xml] cannot be opened because it does not
- class path resource [META-INF/xfire/services.xml] cannot be opened because it does not exist
- spring class path resource [jdbc.properties] cannot be opened because it does not exist
- class path resource [spring.xml] cannot be opened because it does not exist
- class path resource [applicationContext.xml] cannot be opened because it does not exist
- java.io.FileNotFoundException: class path resource ..cannot be opened because it does not exist
- Spring问题:class path resource [xxx.xml] cannot be opened because it does not exist
- class path resource [applicationContext.xml] cannot be opened because it does not exist
- class path resource [spring-mvc.xml] cannot be opened because it does not exist
- java.io.FileNotFoundException: class path resource [META-INF/xfire/services.xml] cannot be opened because it does not exist
- java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not exist 解决方法
- eclipse项目报错怎么解决class path resource [beans.xml] cannot be opened because it does not exist
- IDEA中Spring配置错误:class path resource [.xml] cannot be opened because it does not exist
- linux下zookeeper的安装步骤
- 字符串替换:用参数字符数组成员替换字符串中的占位符(面试题)
- 堆排序
- Eclipse怎样连接并打开oracle等数据库?
- select编程
- class path resource cannot be opened because it does not exits
- struts2上传文件时,关于在action里面获取上传文件的文件名
- Windows下的Python安装pip,及使用技巧
- linux-桥接与网卡聚合
- 动态规划解N个矩阵链乘问题
- Eclipse 运行配置(Run Configuration)
- android studio 出现 failed to find target android- 错误解决的办法
- Java交换排序
- 金币(NOIP2015)