Spring MVC - Using FixedLocaleResolver

[Updated: Jan 10, 2017, Created: Jan 9, 2017]


FixedLocaleResolver always uses a default locale and optionally a time zone. It doesn't allow to change both of them once set. In this tutorial we are only to focus on locale feature only. We can set it's fixed default locale during construction time. If none is set, system locale is used.

public FixedLocaleResolver() {

FixedLocaleResolver is usually needed when we want to turn off the default behavior of AcceptHeaderLocaleResolver. Or we want to switch existing LocaleResolver to a fixed locale for some reasons.

Let's see a quick example how we can use it.

Registering FixedLocaleResolver

If we are using Spring Boot then we have to specify two application properties:



The second property is the fixed default locale of FixedLocaleResolver.

Both properties are mandatory for auto configuration to work.

In a traditional mvc configuration with @EnableWebMVC, we have to register it as a bean:

public class MyConfig{
  LocaleResolver localeResolver(){
     FixedLocaleResolver l = new FixedLocaleResolver();
     return l;

The Controller

public class TheController {

  public String handleRequest (Locale locale) {
      return String.format("Request received. Locale: %s%n",

The main class

public class Main {

    public static void main (String[] args) {
        SpringApplication.run(Main.class, args);


We are using Postman for testing:

Example Project

Dependencies and Technologies Used :
  • spring-boot-starter-web 1.4.3.RELEASE: Starter for building web, including RESTful, applications using Spring MVC. Uses Tomcat as the default embedded container.
    Corresponding Spring version: 4.3.5.RELEASE
  • tomcat-embed-jasper 8.5.6: Core Tomcat implementation.
  • JDK 1.8
  • Maven 3.3.9

Fixed Locale Resolver Example Select All Download
  • fixed-locale-resolver-example
    • src
      • main
        • java
          • com
            • logicbig
              • example
        • resources