Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.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
Spring boot 如何在spring引导应用程序中外部化i18n属性文件_Spring Boot_Internationalization_String Externalization - Fatal编程技术网

Spring boot 如何在spring引导应用程序中外部化i18n属性文件

Spring boot 如何在spring引导应用程序中外部化i18n属性文件,spring-boot,internationalization,string-externalization,Spring Boot,Internationalization,String Externalization,在spring官方文档的帮助下,作为unix服务运行spring boot应用程序时,我成功地将spring boot配置文件(application.properties)外部化到了config文件夹中 我的src/main/resources中还有一些i18nmessages.properties文件,我想在同一个config文件夹中外部化这些文件,但我没有做到。我尝试过很多东西,比如玩spring.messages.basename,但不幸的是,它不起作用 我正在使用最新版本的spring

在spring官方文档的帮助下,作为unix服务运行spring boot应用程序时,我成功地将spring boot配置文件(
application.properties
)外部化到了
config
文件夹中

我的
src/main/resources
中还有一些i18n
messages.properties
文件,我想在同一个config文件夹中外部化这些文件,但我没有做到。我尝试过很多东西,比如玩
spring.messages.basename
,但不幸的是,它不起作用

我正在使用最新版本的spring boot,并使用自动配置模式和默认的i18n属性名称
messages


我错过了什么???谢谢你的帮助。

我想你需要一个前导斜杠


试试看:
spring.messages.basename=classpath:/config/messages

我想,资源包默认为classpath。所以没有必要附加它。只需从类路径直接转到文件夹位置

试试这个:**假设您的配置在静态文件夹中

spring.messages.basename=static/config/messages

请注意:

  • 类路径:消息-将始终查找嵌入的消息\u xxx文件
  • classpath:/messageclasspath:message是等效的

  • 文件:message-将查找jar的外部当前目录,例如../message_en.properties我尝试过:
    spring.messages.basename=classpath:messages
    spring.messages.basename=classpath*:messages
    假设spring配置目录位于类路径上。也许我错了?是的,配置或者jar之外的任何东西都不在类路径上。接下来,它必须是
    config/messages
    作为基本名称。@M.Deinum我已经尝试了
    spring.messages.basename=config/messages
    ,但是如果我这样做,spring找不到翻译。那么
    classpath:config/messages
    ?spring.messages.basename=file:config/messages呢