如何使用spring boot更改embebed-tomcat默认端口?

Jua*_*nao 10 java tomcat spring-boot

我正在使用带有maven的spring-boot,这是我的配置类:

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

应用程序启动时在控制台中显示此行:

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

我想将TomcatEmbedded端口更改为8081.感谢:D

kry*_*ger 30

通过server.port属性设置值,就像文档中所解释的那样,例如:

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

  • 在我的场景中,该方法是:<code> mvn exec:java -Dserver.port = 8081 </ code> (2认同)

bpj*_*shi 6

有3-4种方法可以改变它.在下面添加application.properties

src/main/resources/ 
Run Code Online (Sandbox Code Playgroud)

并将以下属性添加到文件中:

server.port = 8084
Run Code Online (Sandbox Code Playgroud)

有关其他更改方法,请浏览此链接.

Spring官方文档链接相同.