Get all updates of Java4s

Spring Boot – How to Change Default Context Path

Spring-Boot-Tutorials »on Nov 26, 2017 By Sivateja

Firstly what is this context path? simply its our application name. Generally while we are hitting any application in the browser, we will write the URL with the application name(context) right?

I mean…

http://localhost:<port>/<application_name or context_path>/operation_name

But if you check Spring Boot RESTful Web Service Example we haven’t included any context path, we directly ran the application with the path we have given in @RequestMapping, ( go back and have a look once ).

Spring Boot by default consider the context path as ‘/‘ so we no need to give our application name or context path, but in real-time we should use some context path for the applications. In this article I will show you how to change default spring boot application context path ‘/‘ to your application name.

In Spring Boot, we can change application default context path in two ways…

  • Using
  • Using Java code changes

Its very simple just like changing tomcat port number in the previous article :-)


Create in your application src/main/resources and write this line..



Using Java Code Changes

Now we have to run the application by hitting http://localhost:8080/yourApplicationName/, you can download this example and give a try ;)

Note: If we use both java and properties file approaches, spring boot will consider java only.

You Might Also Like

  ::. About the Author .::

- Full Stack Java/J2EE & UI Web Developer
Founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog, Love Java and UI frameworks.
You can sign-up for the Email Newsletter for your daily dose of Java tutorials.



By posting your answer, you agree to our comments policy.
What would you like to learn today?
Browse these popular technologies
Spring-Boot-tutorials Hibernate tutorials Spring tutorials Struts tutorials Servlets tutorials Ajax tutorials Log4j tutorials jQuery tutorials Json tutorials Core Java tutorials Web Services tutorials AngularJs tutorials
Most Recent Tutorials
Hibernate_Logo Hibernate Recent Posts Spring_Logo Spring Recent Posts Struts_Logo Struts Recent Posts
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2018 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.