![](/img/trans.png)
[英]Spring Boot - Where to put properties files when deploying to Tomcat?
[英]Where to put properties files when dealing with internationalization?
我正在尝试在我的程序中进行国际化,我发现了这个简单的示例如何使用它:
package tests;
import java.util.*;
public class I18NSample {
static public void main(String[] args) {
String language;
String country;
if (args.length != 2) {
language = new String("en");
country = new String("US");
} else {
language = new String(args[0]);
country = new String(args[1]);
}
Locale currentLocale;
ResourceBundle messages;
currentLocale = new Locale(language, country);
messages = ResourceBundle.getBundle("MessagesBundle", currentLocale);
System.out.println(messages.getString("greetings"));
System.out.println(messages.getString("inquiry"));
System.out.println(messages.getString("farewell"));
}
}
但每次我编译代码时都会遇到这个异常:
Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name messages, locale en_US
我的文件被命名为 MessagesBundle_en_US.properties 和 MessagesBundle_es_ES.properties,并与 I18NSample class 放在同一个 package 中,所以我认为它应该可以工作。
它应该在类路径的根目录中,因为它默认使用非 package。
否则更改:
messages = ResourceBundle.getBundle("MessagesBundle", currentLocale);
至
messages = ResourceBundle.getBundle("tests.MessagesBundle", currentLocale);
使其与 class 目录/包内的捆绑包一起使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.