Tutorials / Tech blog / Geek Zone

Latest Posts

Tuesday, June 5, 2018

Spring Boot :: Change Default Port

As we all know Spring boot applications get started with embedded Tomcat server. The default application port is 8080. 

Property File

Spring boot provides out of the box pre-configured sensible defaults for many configuration properties. However many a times we might face a situation to alter these properties. One of the most common use case is altering the default port of the embedded tomcat server.

1
server.port=8081

The above change in application.properties file will ensure that the Spring Boot applications gets invoked on port 8081.

This is the most easiest way to customize Spring boot by overriding default values of the properties. The following change in application.properties file will do the trick.


This file can be located at src/main/resources directory of a Maven application.

Configuration via Code

We can also tweak the port pro-grammatically by configuring the relevant property in the main @SpringBootApplication class.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
@SpringBootApplication
public class SpringBootPortChangeApplication {

 public static void main(String[] args) {
  // SpringApplication.run(SpringBootPortChangeApplication.class, args);

  SpringApplication app = new SpringApplication(SpringBootPortChangeApplication.class);
  app.setDefaultProperties(Collections.singletonMap("server.port", "8082"));
  app.run(args);
 }
}

Command Line Arguments

We can also set the server.port property via command line, when packaging and running our application as a uber jar.


1
java -jar springbootportchange.jar --server.port=8083

Priority

So, overall the priority of these configurations is as follows:

  • Command Line Arguments
  • Property files
  • Configuration via Code

1 comment:

  1. The effectiveness of IEEE Project Domains depends very much on the situation in which they are applied. In order to further improve IEEE Final Year Project Domains practices we need to explicitly describe and utilise our knowledge about software domains of software engineering Final Year Project Domains for CSE technologies. This paper suggests a modelling formalism for supporting systematic reuse of software engineering technologies during planning of software projects and improvement programmes in Final Year Project Centers in Chennai.

    Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining the authors explore the idea of using Java in Big Data platforms.
    Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai

    ReplyDelete