How to externalize i18n properties files in spring-boot applications

3.7k Views Asked by At

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.

3

There are 3 best solutions below

0
On BEST ANSWER

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

0
On

I think you need a leading slash.

Try: spring.messages.basename=classpath:/config/messages

0
On

I think, resource bundle is default to classpath. So there's no need to append it. just go straight to your folder location from classpath.

Try this: **assuming your config is inside static folder

spring.messages.basename=static/config/messages