Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change embebed-tomcat default port using spring boot? [duplicate]

I am using spring-boot with maven, this is my configuration class:

package hello;

import javax.servlet.MultipartConfigElement;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

When the app starts show this line in console:

2014-11-06 17:00:55.102  INFO 4669 --- [main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080/http

I want to change the TomcatEmbedded port to 8081 for the case. Thanks :D

like image 868
Juan Henao Avatar asked Nov 06 '14 22:11

Juan Henao


People also ask

Can you change the port of embedded Tomcat server in spring boot?

The Spring Boot framework provides the default embedded server (Tomcat) to run the Spring Boot application. It runs on port 8080. It is possible to change the port in Spring Boot.

How do I run multiple instances of spring boot on a different port?

Where do you set the port? Try using 2 different run configurations with the port set in the VM Options field like this: -Dserver. port=9090 . Use different port for each configuration so that you can run 2 instances.


2 Answers

Set the value via the server.port property, just like explained in the documentation, e.g.:

mvn spring-boot:run -Drun.jvmArguments='-Dserver.port=8081'

like image 70
kryger Avatar answered Sep 28 '22 15:09

kryger


There are 3-4 ways to change it. Add application.properties under

src/main/resources/ 

and add the property as below to the file:

server.port = 8084

For other ways to change, go through this link.

Spring official documentation link for the same.

like image 23
bpjoshi Avatar answered Sep 28 '22 16:09

bpjoshi