Get all updates of Java4s
Newsletter

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 applications.properties
  • Using Java code changes

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

Using application.properties

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

server.contextPath=/yourApplicationName

 

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

Comments

Name*
Mail*
Website



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 - 2017 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.