Internationalization of Spring Boot RESTful Services

Saurav Samantray
2 min readFeb 26, 2021


If your application serves a wide range of clients spanning across the globe, it becomes essential to be able to respond based on country and language of the origin of request. Internationalization is the processes of designing your application to be capable of the same. During the course of this article we will create a simple Spring Boot App with a single endpoint that can serve the same text in various languages.

Code Structure

│ .gitignore
│ mvnw
│ mvnw.cmd
│ pom.xml

│ ├───java
│ │ └───com
│ │ └───techgoons
│ │ └───i18n
│ │
│ │
│ │
│ └───resources


You can use the spring boot initializer to generate the template with spring-boot-starter-web dependency.

How to enable i18n messaging in a spring boot app?

Update the as below. Explanation for each configuration has been added as comments

Resource Bundles

As specified in the, application will look for messages*.properties named files for fetching content. — the default file will contain English key value pairs

welcome=Welcome to Tech Goons homepage — German

welcome=Willkommen auf der Tech Goons-Homepage — Spanish

welcome=Bienvenido a la página de inicio de Tech Goons — French

welcome=Bienvenue sur la page d'accueil de Tech Goons — Dutch

welcome=Welkom op de startpagina van Tech Goons

All translations have been generated using Google translate. Apologies in advance if certain translations are not correct.

Rest Controller

We will keep the controller simple and expose just a single endpoint that will fetch the welcome message from resource bundle based on Accept-Language header in the request.

We autowire the MessageSource component which has the necessary means to fetch values from appropriate resource bundle based on language details passed in request header.


After starting the server you can try out below cURL commands.

curl --location --request GET 'localhost:8080/' --header 'Accept-Language: de'OUTPUT: Willkommen auf der Tech Goons-Homepagecurl --location --request GET 'localhost:8080/' --header 'Accept-Language: es'OUTPUT: Bienvenido a la p�gina de inicio de Tech Goons

Source code here. Happy Learning!