Spring Boot: Bootstrapping a web server

Spring Boot auto-configures an embedded Tomcat server the moment spring-boot-starter-web is on the classpath. A single @SpringBootApplication annotation on your main class combines @Configuration, @EnableAutoConfiguration, and @ComponentScan, getting a production-capable web server running with zero XML. This article covers project setup, the application entry point, and changing the default port.

When the jar present in class path, and when the application it automatically configures and starts a Tomcat server that is embedded inside this jar.

Contents

Bootstrapping a web server

How to change default port number for web server

As you see in above example, Tomcat server started with default port number 8080, if you want to change the port number, you can suply server.port property in different ways.

  • You can supply server.port as JVM argument, -Dserver.port=9090
  • You can supply server.port as application argument, --server.port=9090
  • In case if you specify both, application argument --server.port value takes precedence.
  • You can supply it through Spring's application.properties file or application.yml file.
  • Below is an example specifying port number as 9090 in application.properties.

    server.port=9090

    Below is an example specifying port number as 9090 in application.yaml.

    YAML
    server:
      port: 9090