假设有多个属性文件
captions.properties
captions_es_ES.properties
captions_cn_CN.properties
captions_th_Th.properties
当前在 Tomcat 上,如果调用
ResourceBundle.getBundle("someCaption");
获取属性值没有问题
但是,当在 Websphere 中部署应用程序时,如果 local 为 en_US 并调用上述相同代码,则应用程序总是抛出 MissingResourceException
但同一行在任何其他外国语言环境上都可以正常工作。
如果我强制执行像 Locale.ROOT 这样的语言环境,那么它当然可以工作,但我认为 geBundle(str) 方法应该默认检查默认属性,无论如何
我可以保证“someCaption”存在于所有语言属性文件中。
最佳答案
这看起来是规范/预期的行为——也许您的 native 环境在 Tomcat 和 WebSphere 启动之间有所不同?
https://docs.oracle.com/javase/7/docs/api/java/util/ResourceBundle.html#getBundle(java.lang.String)
Gets a resource bundle using the specified base name, the default locale, and the caller's class loader.
您可以检查 Locale.getDefault()
在两个环境中是否不同。
关于java - 为什么 ResourceBundle.getBundle(String str) 无法从 Websphere 中的默认属性文件中找到值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34956302/