How to change the server's port number in spring boot

problem

You have a Java web application that uses Spring Boot and you wish to change the default port number (i.e. 8088) the web server is running on.

SOLUTION 1

One solution is by specifying the preferred port number in the application.properties file as follows:

application.properties
				
					server.port=8081
				
			
running

When the program runs the server port should show the one specified above i.e. 8081

Correct! The port number is 8081

SOLUTION 2

Using Virtual Machine (VM) arguments and specifying the following key-value pair:

				
					-Dserver.port=9999
				
			

If you’re using IntelliJ IDE, it can be specified in the run configuration as shown in the screenshot below:

running

conclusion

In this post we saw two different ways for changing the default server port in Spring Boot.

Share it!

Facebook
Twitter
LinkedIn
Reddit
Picture of Ellion

Ellion

Professional IT consultant, writer, programmer enthusiast interested in all sorts of coding.
Eats all cookies 🍪

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x