简体   繁体   English

如何通过命令提示符在指定端口启动spring boot tomcat服务器

[英]How to start a spring boot tomcat server on a specified port through command prompt

I have a very simple "Hello World" kind of REST api created using Spring Boot that is accessible through http://localhost:8080/greeting/world without any problem.我有一个使用 Spring Boot 创建的非常简单的“Hello World”REST api,可以通过http://localhost:8080/greeting/world 访问,没有任何问题。

I would like to start two more instances of this API on ports 8081 and 8082 but not able to do so.我想在端口 8081 和 8082 上启动此 API 的另外两个实例,但无法这样做。 It says java.net.BindException: Address already in use: bind它说java.net.BindException: Address already in use: bind

Command Used:使用的命令:

mvn spring-boot:run -Dserver.port=8081

application.yml应用程序.yml

spring:
  application:
    name: world-greeting-service

WorldGreetingServiceApplication.java WorldGreetingServiceApplication.java

@RestController
@SpringBootApplication
public class WorldGreetingServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(WorldGreetingServiceApplication.class, args);
    }

    @RequestMapping("/greeting/world")
    public String greetWorld() {
        return "Hello World!";
    }

}

Am I missing anything?我错过了什么吗?

尝试使用,

mvn spring-boot:run -Drun.jvmArguments='-Dserver.port=8081'
java -jar world-greeting-service.jar --server.port=8081

此命令等效于上述答案,可以在未安装maven时使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM