项目是jar包启动。如何配置spring.messages.basename国际化文件 引用外部文件
时间: 2024-04-15 16:29:52 浏览: 125
如果你想在以 JAR 包形式启动的项目中配置 `spring.messages.basename` 属性来引用外部的国际化文件,可以按照以下步骤进行操作:
1. 首先,将你的国际化文件(例如 `messages.properties`)放置在一个外部目录中,可以是项目的根目录或者指定的配置目录。
2. 创建一个新的配置文件(例如 `application.properties`),将 `spring.messages.basename` 属性设置为你的国际化文件的路径和基本名称。例如:
```properties
spring.messages.basename=file:/path/to/your-external-folder/messages
```
这里的 `/path/to/your-external-folder/` 是你放置国际化文件的外部目录的路径。
3. 确保将该 `application.properties` 文件与 JAR 包放置在同一目录下。
4. 使用以下命令启动你的 JAR 包:
```shell
java -jar your-application.jar --spring.config.name=application --spring.config.location=file:/path/to/your-application.properties
```
这样,Spring Boot 将会加载外部的 `application.properties` 文件,其中包含了 `spring.messages.basename` 的配置。
这样配置后,Spring Boot 将会根据 `spring.messages.basename` 属性指定的路径去查找国际化文件。请确保国际化文件的路径和基本名称与配置一致,并且具有正确的访问权限。
希望这些步骤对你有所帮助!如有任何疑问,请随时提问。
阅读全文
相关推荐











