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");
将项目的包名从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.util.MissingResourceException Can't find bundle for base name
- Can't find bundle for base name DBInfo, locale zh_CN解决方法
- 解决ofbiz在myeclipse中调试运行时报错:Can't find bundle for base name cache
- 解决java.util.MissingResourceException: Can't find bundle for base name configContext, locale zh_CN
- Android studio中遇到Can't find bundle for base name configd, locale zh_CN解决办法
- Can't find bundle for base name Message, locale zh_CN
- Can't find bundle for base name 包名.xxxx.文件名,locale 语言简称_国家简称
- java.util.MissingResourceException: Can't find bundle for base name
- Notes for "java.util.MissingResourceException Can't find bundle for base name"
- Can't find bundle for base name javax.servlet.LocalStrings, locale zh_CN解决方案
- Can't find bundle for base name
- Can't find bundle for base name javax.servlet.LocalStrings, locale zh_CN错误处理
- Can't find bundle for base name MessageResource, locale zh_CN
- 关于:java.util.MissingResourceException: Can't find bundle for base name merchantInfo, locale zh_CN
- 关于SpringMVC MockMvc测试 Can't find bundle for base name javax.servlet.LocalStrings, locale zh_CN错误
- Solve java.util.MissingResourceException: Can't find bundle for base name com...config, locale zh_CN
- 安装CentOS7文字界面版后,无法联网,用yum安装软件提示 cannot find a valid baseurl for repo:base/7/x86_64 的解决方法
- 安装CentOS7文字界面版后,无法联网,用yum安装软件提示 cannot find a valid baseurl for repo:base/7/x86_64 的解决方法
- Navicat连接数据库Can't get hostname for your address 解决方法
- mysql远程访问出现MySQL错误1042-Can't get hostname for your address解决方法