Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to externalize i18n properties files in spring-boot applications

I’ve succeed to externalize my spring-boot configuration file (application.properties) in a config folder when I run my spring-boot application as a unix service with the help of the official spring documentation https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

I have also some i18n messages.properties files in my src/main/resources that I would like to externalize in the same config folder but I failed to do it. I’ve tried a lot of things, like playing with spring.messages.basename but unfortunately, it doesn’t work.

I’m using the latest version of spring-boot, and use auto configure mode with the default i18n properties name messages.

What am I missing??? thanks for your help.

like image 751
Fabrice Deshayes Avatar asked Nov 06 '25 21:11

Fabrice Deshayes


1 Answers

Just a few notes:

  1. classpath:message - will always lookup embeded message_xxx files
  2. classpath:/message and classpath:message are equivalent
  3. file:message - will lookup jar's external current directory e.g. ./message_en.properties <- this is what you want

  4. file:/message - you have to put your message files to root "/" to make it work

  5. use notation file:config/message if you need to put in config folder together with your ./config/application.properties

like image 70
Johnny Chong Avatar answered Nov 08 '25 11:11

Johnny Chong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!