Maven ResourceBundle.getBundle读取Properties异常MissingResourceException: Can't find bundlei解决方法

 

参考:https://blog.csdn.net/thousa_ho/article/details/72817616

 

问题描述

ResourceBundle读取properties配置文件提示

MissingResourceException: Can not find bundle for base name resource.properties

reource.properties放在resources目录【classpath目录下】

始终提示找不到该文件

 

 

原因

classpath下的文件编译后放在classes目录下,与项目根目录同级!

 

ResourcesBundle如果读取的文件带有“properties”后缀名,则它会从工程根目录下找;而如果要到classes下去寻找,则要去掉后缀!

解决方法

去掉properties后缀即可

ResourceBundle resourceBundle = ResourceBundle.getBundle("resource", Locale.getDefault());

 



 

posted @ 2018-10-18 19:41  山人是我师  阅读(1758)  评论(0编辑  收藏  举报