Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Kubernetes上的Spring引导应用程序如何使用external message.properties文件支持i18n和l10n?_Java_Spring Boot_Kubernetes_Internationalization - Fatal编程技术网

Java Kubernetes上的Spring引导应用程序如何使用external message.properties文件支持i18n和l10n?

Java Kubernetes上的Spring引导应用程序如何使用external message.properties文件支持i18n和l10n?,java,spring-boot,kubernetes,internationalization,Java,Spring Boot,Kubernetes,Internationalization,我们有一个部署到Kubernetes的spring引导应用程序。我们正在向这个应用程序添加i18n功能,并希望将messages.properties文件放在应用程序jar/war之外。我已经能够做到这一点,在春季开机。当我将它部署到Kubernetes上时,它将如何工作?我需要使用configmaps吗?下面是代码片段 @Configuration public class AppConfig { @Bean public MessageSource messageSource() {

我们有一个部署到Kubernetes的spring引导应用程序。我们正在向这个应用程序添加i18n功能,并希望将messages.properties文件放在应用程序jar/war之外。我已经能够做到这一点,在春季开机。当我将它部署到Kubernetes上时,它将如何工作?我需要使用configmaps吗?下面是代码片段

@Configuration
public class AppConfig {
@Bean
public MessageSource messageSource() {
    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    //Path to the messages.properties files
    messageSource.setBasenames("file:/messages/messages", "classpath:messages");
    messageSource.setDefaultEncoding("UTF-8");
    messageSource.setCacheSeconds(60);
    return messageSource;
}
}

是的,您可以使用configmap执行此操作。这与访问外部application.properties文件大致相同。首先,您可以创建一个:

然后在kubernetes部署中创建一个和:


这些代码段来自application.properties文件的,因此它们使用
/config
的spring引导。您可以这样装载文件,以便使用在kubernetes之外运行时已使用的相同相对路径。

Ryan,如果我有10种语言的messages.properties,我是否应该为所有语言创建配置映射?例如:一个用于messages.properties,一个用于messages\u fr\u fr.properties等等。应用程序代码中需要做哪些更改?我的应用程序如何理解它必须从configMap文件读取,或者它对此不可知?我是Kubernetes的新手,找不到有关此的信息。您可以在同一个configmap中包含多个文件,它们将全部装入目录中。要向上面的示例中添加更多文件,您需要将它们放置在与application.properties相同的yaml缩进级别。应用程序可以像访问任何其他目录一样访问装载的目录。它不需要知道目录是如何到达那里的。什么是正确的挂载路径或其他K8S魔法咒语来获得这种行为-挂载路径应该是“/”而不是“/config”?根据它应该是/config
apiVersion: v1
kind: ConfigMap
metadata:
  name: treasurehunt-config
  namespace: default
data:
  application.properties: |
    treasurehunt.max.attempts=5
          volumeMounts:
          - name: application-config
            mountPath: "/config"
            readOnly: true
      volumes:
      - name: application-config
        configMap:
          name: treasurehunt-config
          items:
          - key: application.properties
            path: application.properties