gpt4 book ai didi

java - Kubernetes 上的 Spring Boot 应用 如何使用外部 message.properties 文件来支持 i18n 和 l10n?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:07:19 26 4
gpt4 key购买 nike

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

@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;
}
}

最佳答案

是的,您可以使用配置图来做到这一点。它与访问外部 application.properties 文件非常相似。首先你可以create a ConfigMap directly from the file或者创建一个 ConfigMap representing the file :

apiVersion: v1
kind: ConfigMap
metadata:
name: treasurehunt-config
namespace: default
data:
application.properties: |
treasurehunt.max.attempts=5

然后在您的 kubernetes 部署中创建一个 Volume for the ConfigMapmount that into the Pod under the directory you use for the external configuration :

          volumeMounts:
- name: application-config
mountPath: "/config"
readOnly: true
volumes:
- name: application-config
configMap:
name: treasurehunt-config
items:
- key: application.properties
path: application.properties

这些片段来自 example of mounting a Volume from ConfigMap对于 application.properties 文件,因此他们使用 spring boot default external properties file path /配置。你可以set that in the yaml for the mount因此您可以挂载文件以使用您在 kubernetes 外部运行时已经使用的相同相对路径。

关于java - Kubernetes 上的 Spring Boot 应用 如何使用外部 message.properties 文件来支持 i18n 和 l10n?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53001506/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com