Java异常 :BeanDefinitionStoreException
来源:互联网 发布:北航网络教育平台 编辑:程序博客网 时间:2024/05/23 19:44
Java异常 :BeanDefinitionStoreException
#
本文讲述的是因为版本问题引发的该异常
import java.io.InputStream;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import java.util.Properties;/** * Created by 谭健 on 2017/8/15. 14:41. * © All Rights Reserved. */public class Reader { public static Map<String, Object> readPropertiesToHashMap(final String name) { Properties properties = new Properties(); InputStream io = Reader.class.getResourceAsStream(name); HashMap<String, Object> stringObjectHashMap = new HashMap<>(); try { properties.load(io); Iterator<String> iterator = properties.stringPropertyNames().iterator(); /** * 即使你的项目已经从Java6切换到Java8,使用JDK 1.8 * 使用Lambda表达式并不会报错,并且可以测试运行通过 * 但是你仍然不能使用Lambda的forEach进行迭代 * 他会导致Spring在初始化的时候抛出异常:BeanDefinitionStoreException * 提示你读取组件类失败,因为发生了数组越界异常 * 你需要继续使用原来的迭代方式 */ while (iterator.hasNext()) { /** * 在这里有一个注意点,你不能使用 * stringObjectHashMap.put(iterator.next(), properties.getProperty(iterator.next())); * 这种方式来进行迭代,他会导致迭代比预期次数减少一倍 * 因为每使用一次iterator.next(),都会将迭代器向后迭代一次 * 你进行的两处引用,会导致迭代器每一次迭代向后两步 */ String key=iterator.next(); stringObjectHashMap.put(key, properties.getProperty(key)); }// you can't use this code ,because is will initiation BeanDefinitionStoreException// Failed to read candidate component class : nested exception is java.lang.ArrayIndexOutOfBoundsException//// The reason is that the JDK version is inconsistent////// properties.stringPropertyNames()// .iterator()// .forEachRemaining(// key ->// stringObjectHashMap.put(key, properties.getProperty(key))// ); } catch (Exception e) { e.printStackTrace(); } return stringObjectHashMap; } public static void main(String[] args) { System.out.println(readPropertiesToHashMap("/config/config.properties")); }}
阅读全文
2 0
- Java异常 :BeanDefinitionStoreException
- Spring异常之BeanDefinitionStoreException
- org.springframework.beans.factory.BeanDefinitionStoreException异常处理
- 初学spring Boot 启动异常BeanDefinitionStoreException
- Spring容器初始化异常:org.springframework.beans.factory.BeanDefinitionStoreException
- Spring BeanDefinitionStoreException
- java 异常,java,异常
- Java 异常 异常链
- org.springframework.beans.factory.BeanDefinitionStoreException
- org.springframework.beans.factory.BeanDefinitionStoreException:
- org.springframework.beans.factory.BeanDefinitionStoreException
- org.springframework.beans.factory.BeanDefinitionStoreException:
- org.springframework.beans.factory.BeanDefinitionStoreException
- org.springframework.beans.factory.BeanDefinitionStoreException
- org.springframework.beans.factory.BeanDefinitionStoreException
- org.springframework.beans.factory.BeanDefinitionStoreException
- org.springframework.beans.factory.BeanDefinitionStoreException
- org.springframework.beans.factory.BeanDefinitionStoreException:
- Greenplum4.3管理员指南
- 通达OA2017破解补丁,通达oa破解版,通达oa最新破解版
- 装完WIN2008如何在桌面显示图标
- 面试总结
- AngularJS集成自动化测试
- Java异常 :BeanDefinitionStoreException
- 竞赛题目讲解-【Rocky Mountain 2004】最短前缀
- NYOJ 1316 Interval
- leetcode 474. Ones and Zeroes
- HTML5-angular中的Ui route
- 20170818周末记账流水(2017-08-18 10:00)
- Chrome插件 helloWord
- 欢迎使用CSDN-markdown编辑器
- java:警惕Integer.MAX_VALUE造成的死循环