简体   繁体   English

Spring Boot 不遵守命令行参数

[英]Spring Boot not obeying command line arguments

Put together a very basic Spring Boot RESTful backend with some CRUD endpoints.将一个非常基本的 Spring Boot RESTful 后端与一些 CRUD 端点组合在一起。 Trying to start it up on my Centos7 server.尝试在我的 Centos7 服务器上启动它。 However I already have an application listening on its default port, 8080, so I have to configure that.但是,我已经有一个应用程序侦听其默认端口 8080,因此我必须对其进行配置。

I have tried:我试过了:

java -jar target/rest-1.0-SNAPSHOT.jar --server.port=8090

java -jar target/rest-1.0-SNAPSHOT.jar --Dserver.port=8090

java -jar target/rest-1.0-SNAPSHOT.jar --port=8090

java -jar target/rest-1.0-SNAPSHOT.jar --Dport=8090

My application.properties contains the line:我的 application.properties 包含以下行:

server.port=${port:8090}

Spring Boot still starts up the embedded Tomcat container on port 8080. It's not getting the message. Spring Boot 仍然在端口 8080 上启动嵌入式 Tomcat 容器。它没有收到消息。 What am I missing?我错过了什么?

Edit: setting SERVER_PORT=8090 was effective - see below编辑:设置SERVER_PORT=8090有效 - 见下文

Try with -Dserver.port=8090 note single - or server.port=xxxx in application.properties file尝试在 application.properties 文件中使用-Dserver.port=8090 note single -server.port=xxxx

EDIT:-编辑:-

Check your log, below line will echo in console 2015-10-16 23:13:23.082 INFO 4228 --- [ main] sbcetTomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8090 (http)检查您的日志,以下行将在控制台中回显2015-10-16 23:13:23.082 INFO 4228 --- [ main] sbcetTomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8090 (http)

VM arg overrides application.properties VM arg 覆盖 application.properties

If you have a "application.yml" or "application.properties" in the same folder of jar, the jar will take preference of the external configuration file.如果 jar 的同一文件夹中有“application.yml”或“application.properties”,则 jar 将优先使用外部配置文件。 Doesnt make sense for me, but its true.对我来说没有意义,但它是真的。 The springboot has higher priority to external configuration file instead the internal one. springboot 优先于外部配置文件而不是内部配置文件。

We have four different ways to change default port.我们有四种不同的方法来更改默认端口。

  1. Using application.properties or application.yml使用 application.properties 或 application.yml
  2. Implementing EmbeddedServletContainerCustomizer interface实现 EmbeddedServletContainerCustomizer 接口
  3. Using SpringApplication class使用 SpringApplication 类
  4. Change port directly through command line直接通过命令行更改端口

For more details, visit below http://www.javainterviewpoint.com/spring-boot-change-embedded-tomcat-default-port/有关更多详细信息,请访问以下http://www.javainterviewpoint.com/spring-boot-change-embedded-tomcat-default-port/

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

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