Spring Boot change tomcat port Example

Home / Spring Boot change tomcat port Example

In this post we will see spring boot change tomcat port example. As we Know by default spring boot application on port 8080. And some time we have to change this running port if some other application is already running on 8080 port.

And we also know spring boot provides embedded tomcat server, we don’t have to install tomcat explicitly and add it to our Eclipse IDE.

It is very simple to change port of Tomcat in spring boot You juts have to go to your application.properties file and add below properties there.

server.port=8989

Here i am giving 8989 port. Now if i run my application than it will run on port 8989 and my URL will be.

http://localhost:8989

But sometimes we have to change the by default running port number if any application is running on port 8080 or the given port. So here the spring boot change tomcat port topic comes.

you can check if any application running on port 8080 in windows using following command:

1- open cmd and type below command

netstat -ano | findstr :8080

If anything running on port 8080 then you will get output like

TCP    0.0.0.0:8080           0.0.0.0:0              LISTENING       12412
TCP    [::]:8080              [::]:0                 LISTENING       12412

if you want to free the port 8080 then you have to use the below command

taskkill /PID 12412 /F

No your port 8080 is free now you can run your spring boot application on this port.

And if you are using the Linux OS then you can use the below commands.

1- To check if 8080 port is already occupied by any other application or not. Use below command in your linux console.

netstat -alnp | grep 8080

And if anything application is running on this application than you can use below command to free 8080 port.

kill -9 8539

In above command 8539 is a pid which you will get when you run the netstat command for checking port is free or not.

Now suppose there is already a application running on port 8080 and you don’t want to kill that process that is running on port 8080 and you also want to run your tomcat. so you have to change the port of your server.

for changing port go to application.properties file and add the below line

server.port=8082

Now run your Spring boot project. At this time your application is running on port 8082. So your Spring Boot project URL will be like

http://localhost:8082

You may also like:

How to use H2 database in spring boot application

How to read property values in spring boot application

Spring Boot With MySql

Spring boot cache example

Swagger2 in Spring Boot

Refrence:

Spring boot official docs.

Help Others, Please Share

About Author

Leave a Reply

Your email address will not be published. Required fields are marked *