【问题标题】:How to start a spring boot tomcat server on a specified port through command prompt如何通过命令提示符在指定端口启动spring boot tomcat服务器
【发布时间】:2018-04-27 23:00:15
【问题描述】:

我有一个使用 Spring Boot 创建的非常简单的“Hello World”类型的 REST api,可以通过 http://localhost:8080/greeting/world 毫无问题地访问。

我想在端口 8081 和 8082 上再启动两个此 API 的实例,但无法这样做。它说java.net.BindException: Address already in use: bind

使用的命令:

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

application.yml

spring:
  application:
    name: world-greeting-service

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!";
    }

}

我错过了什么吗?

【问题讨论】:

  • 您是否检查过端口 8080、8081、8082 尚未使用?你能给我们一个完整的错误信息吗?

标签: java spring spring-mvc spring-boot microservices


【解决方案1】:

尝试使用,

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

【讨论】:

    【解决方案2】:
    java -jar world-greeting-service.jar --server.port=8081
    

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

    【讨论】:

      猜你喜欢
      • 2013-05-17
      • 2022-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-28
      • 2021-04-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多