{{announcement.body}}
{{announcement.title}}

Spring Boot Configuration: Overriding Built-In Configuration

DZone 's Guide to

Spring Boot Configuration: Overriding Built-In Configuration

Learn more about overriding built-in Spring Boot configurations.

· Java Zone ·
Free Resource

Spring built-in configuration

Learn more about overriding built-in Spring Boot configurations.

The Context and Dependency Injection is one of the main features in Java frameworks and APIs. Spring Boot supports configuration in an intuitive way. In this article, we will tackle configuration in Spring Boot by overriding the existing configuration.

You may also like: All About Spring Boot [Articles and Tutorials]

Introduction

To make a configuration in Spring Boot, you need to create a class and annotate it with @Configuration. Usually, in the configuration class, you can define a beans object. But if you want to override built-in configuration, you need to create a new class that extends the built-in class. This includes built-in configurations like security, templating, etc.

Overriding Built-In Configuration

By default, the URL path of the web service is case sensitive. For example:

http://localhost:8080/HelloWorld != http://localhost:8080/helloworld

So, we will make them equal to each other by overriding this configuration. To achieve the goal, we will create a new configuration Class that extends WebMvcConfigurationSupport. Then, we’re going to override configurePathMatch method, as shown below:

package com.hashimati.io.demo.overrideconfig.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.util.AntPathMatcher;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
@Configuration
public class PathConfig extends WebMvcConfigurationSupport {
    @Override
    protected void configurePathMatch(PathMatchConfigurer configurer) {
        configurer.setPathMatcher(new AntPathMatcher(){{
            setCaseSensitive(false);
        }}
        );
    }
}


After running the application, any service path will not be case sensitive. The source code is available here.

Further Reading

All About Spring Boot [Articles and Tutorials]

Spring Boot: The Most Notable Features You Should Know

Topics:
spring boot ,java ,configuration ,built-in ,config

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}