DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Actuator Enhancements: Spring Framework 6.2 and Spring Boot 3.4
  • How Spring Boot Starters Integrate With Your Project
  • A Practical Guide to Creating a Spring Modulith Project
  • Structured Logging in Spring Boot 3.4 for Improved Logs

Trending

  • Your AI Agent Tests Are Passing, But Your Agent Is Still Broken
  • Feature Flag Debt: Performance Impact in Enterprise Applications
  • Beyond Manual Annotation: Engineering Self-Correcting Pseudo-Labeling Pipelines
  • OpenAPI From Code With Spring and Java: A Recipe for Your CI
  1. DZone
  2. Coding
  3. Frameworks
  4. Spring Boot Configuration: Overriding Built-In Configuration

Spring Boot Configuration: Overriding Built-In Configuration

Learn more about overriding built-in Spring Boot configurations.

By 
Ahmed Al-Hashmi user avatar
Ahmed Al-Hashmi
·
Updated Jan. 02, 20 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
30.2K Views

Join the DZone community and get the full member experience.

Join For Free

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

Spring Framework Spring Boot

Opinions expressed by DZone contributors are their own.

Related

  • Actuator Enhancements: Spring Framework 6.2 and Spring Boot 3.4
  • How Spring Boot Starters Integrate With Your Project
  • A Practical Guide to Creating a Spring Modulith Project
  • Structured Logging in Spring Boot 3.4 for Improved Logs

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook