12

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

Thomas Traude
  • 840
  • 7
  • 17
Juan Henao
  • 220
  • 1
  • 3
  • 14

4 Answers4

35

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'

kryger
  • 12,906
  • 8
  • 44
  • 65
7

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.

bpjoshi
  • 1,091
  • 16
  • 23
0

Use double quote:

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

robin
  • 24
  • 1
  • 1
    Single quotes work just as well - otherwise this is an exact duplicate of the long-accepted answer. – kryger Sep 06 '16 at 10:01
-2

Write this in application.yml:

server:
  port: [your port]

for example

server:
  port:8888

to change the default port to 8888

kryger
  • 12,906
  • 8
  • 44
  • 65
grey zeng
  • 37
  • 2