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

0

4 Answers 4

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'

Sign up to request clarification or add additional context in comments.

1 Comment

in my scenario, this workds: <code>mvn exec:java -Dserver.port=8081</code>
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.

Comments

0

Use double quote:

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

1 Comment

Single quotes work just as well - otherwise this is an exact duplicate of the long-accepted answer.
-2

Write this in application.yml:

server:
  port: [your port]

for example

server:
  port:8888

to change the default port to 8888

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.