Get all updates of Java4s

Spring Boot – How to Change Default Tomcat Server Port

In our previous RESTful example, when we start the application Spring Boot’s inbuilt tomcat server by default will take 8080 as its port number, did you observe that :-) go back and have a look once. In this article, I am going to show you how to change that default tomcat’s port number 8080 to something else.

In Spring Boot, we can change tomcat’s port number in 2 ways…

  • Using
  • Using Java code change

Firstly, let me show you using Consider the previous Creating a RESTful Web Service Example, here I just created file in src/main/resources no other changes.

Structure looks

server.port = 2017


A single line server.port will change the Spring Boot tomcat’s port number, if you run the application the server will takes 2017 as its port number, you can check the port in the console and can execute the application.



Using Java code change

In this approach, we will create a simple java class which implements EmbeddedServletContainerCustomizer interface of Spring Boot, this is a strategy interface for customizing auto-configured embedded servlet containers, and we need to override customize() method of that interface that’s it, let me show you an example.

Directory Structure

I have created a java class in package with name

If you run the application, now the server will consider 2018 as its port number.


Note: If you use both and Java config, Spring Boot will give preference for Java only, I mean it takes 2018 as its tomcat port number, you can download this example and give a try ;)

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.


One Response to “Spring Boot – How to Change Default Tomcat Server Port”
  1. Ashwin Kumar says:

    My property file was not getting detected even after making necessary changes. Later found that we need to remove the exclusion of resources folder in the project build path.
    Project Properties –> Java Build Path –> Source(tab) –> Source folders on build path: [Exclusion section]


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.