您的位置:首页 > 编程语言 > Java开发

Can't find bundle for base name 的解决方法

2017-07-14 17:24 881 查看
打包后找不到配置文件

将项目的包名从dmc.ihangmei.com 变更为com.ihangmei.heartbeat后,原先能能够获取的配置信息也不能获取了。

异常如下:

D:\Users\zp\git\heartbeatProject\target>

D:\Users\zp\git\heartbeatProject\target>java -jar 1231-jar-with-dependencies.jar

2017-07-14 17:11:34 Heartbeat init.0: Can't find bundle for base name config/device, locale zh_CN

java.util.MissingResourceException: Can't find bundle for base name config/device, locale zh_CN

at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1564)

at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1387)

at java.util.ResourceBundle.getBundle(ResourceBundle.java:773)

at com.ihangmei.heartbeat.Heartbeat.initDevConfig(Heartbeat.java:316)

at com.ihangmei.heartbeat.Heartbeat.submain(Heartbeat.java:116)

at com.ihangmei.heartbeat.Heartbeat.main(Heartbeat.java:105)

代码如下:

ResourceBundle resourceBundle = ResourceBundle.getBundle("config/device");

网上查找资料,如下:

Solve java.util.MissingResourceException: Can't find bundle for base name com...config, locale zh_CN

at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:836)

at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:805)

at java.util.ResourceBundle.getBundle(ResourceBundle.java:576)

You know Java is looking for a properties file in a specific locale. You may be baffled why java keeps complaining it can't find a properties file that is right there. A few things to keep in mind when debugging this type of errors:

1. These resource properties files are loaded by classloader, similar to java classes. So you need to include them in your runtime classpath.

2. These resources have fully-qualified-resource-name, similar to a fully-qualified-class-name, excerpt you can't import a resource into your java source file. Why? because its name takes the form of a string.

3. ResourceBundle.getBundle("config") tells the classloader to load a resource named "config" with default package (that is, no package). It does NOT mean a resource in the current package that has the referencing class.

4. ResourceBundle.getBundle("com.cheng.scrap.config") tells the classloader to load a resource named "config" with package "com.cheng.scrap." Its fully-qualified-resource-name is "com.cheng.scrap.config"

修改代码,重新指定其详细地址。变为如下,问题解决。

ResourceBundle resourceBundle = ResourceBundle.getBundle("com.ihangmei.heartbeat.config.device");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java
相关文章推荐