Tomcat Server takes by default 8080 port. i.e When you deploy your Spring Boot Application on Tomcat Server and want to run it, you have to enter an address like localhost:8080 or www.solutionfactory.in:8080 or ip-address/8080 But what if you want to change this port address(8080) to something else, then how to do it. Let?s see how to change default Tomcat Server Port 8080 in Spring Boot.
In Spring Boot Application, you can change Tomcat Server Port by two ways,
Spring boot introduced its default application properties named as "application.properties" file which is stored inside "src/main/resources" directory and it is auto detected without doing any spring based configurations.
server.port will change the Spring Boot tomcat's port number to 1299 but you are free to modify it as per your wish, if you run the application the tomcat server will take 1299 as its port number, you can check the port in the console and then execute the application on this port.
Using Java code, we will have to create a simple java class which implements EmbeddedServletContainerCustomizer interface of Spring Boot, this is the interface that is provided for customizing auto-configured embedded servlet containers, and after implementing the interface EmbeddedServletContainerCustomizer we need to override its customize() method. Let us see this using an Example
Now when you run the application, the server will have port number 1200.