java - 具有不同区域设置的客户端和服务器 - 后备机制

标签 java jboss

我有 jboss 服务器以 fr_CH 语言环境运行,应用程序客户端以 de_CH 语言环境运行。我有两个包 - messages.properties(root) 和 messages_fr_CH.properties。这很奇怪,但是在服务器端,ResourceBundle.getBundle("bundleLocation", new Locale("de","CH")) 返回 fr_CH 语言环境的包而不是根包。

我唯一能想到的是,在服务器端 Locale.getDefault() 是“fr_CH”,但如果我做对了,由于优雅降级的概念,标准 java 后备机制不应该关心它......

还有其他想法可能是什么问题吗?

谢谢, 一月

最佳答案

您是对的,此行为是由于默认区域设置造成的。查看javadoc ResourceBundle.getBundle:

getBundle uses the base name, the specified locale, and the default locale (obtained from Locale.getDefault) to generate a sequence of candidate bundle names. If the specified locale's language, country, and variant are all empty strings, then the base name is the only candidate bundle name. Otherwise, the following sequence is generated from the attribute values of the specified locale (language1, country1, and variant1) and of the default locale (language2, country2, and variant2):

baseName + "_" + language1 + "_" + country1 + "_" + variant1
baseName + "_" + language1 + "_" + country1
baseName + "_" + language1
baseName + "_" + language2 + "_" + country2 + "_" + variant2
baseName + "_" + language2 + "_" + country2
baseName + "_" + language2
baseName

所以你的情况是baseName +“_”+ language2 +“_”+country2

关于java - 具有不同区域设置的客户端和服务器 - 后备机制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9687151/

相关文章:

java - Jboss 上的 Drools 项目使用什么 Maven 3 原型(prototype)?

java - C++中的JNI读取文件到jbyteArray

java - Camel 路由发布者未发布到 JMS 出站队列失败,并出现 java.util.concurrent.RejectedExecutionException

java - 如何读取位于项目文件夹java中的文件

java - 面向对象设计,设计一棵树

deployment - Jboss 7 war 部署失败

Java字符串解析和通过MIDI合成器播放错误

jakarta-ee - JBOSS 和 Tomcat6 的加密数据源密码

session - 单页应用,无 cookie,tomcat session 管理

jboss - 在 wildfly 8.2 中的 standalone-full.xml 中设置系统属性