[英]Java: How to change mongodb port configured with spring boot yml
With java I can do the following to change the tomcat port: 使用Java,我可以执行以下操作来更改tomcat端口:
java -jar spring-5.jar --server.port=8083
That works for changing the default 8080 port in my yml file but what if I also want to change the default mongo db port: 这适用于更改yml文件中的默认8080端口,但是如果我也想更改默认的mongo db端口怎么办:
spring:
data:
mongodb:
database: test
host: localhost
port: 27017
can I do: 我可不可以做:
java -jar spring-5.jar --mongodb.port=27018
Will the above work? 以上工作有效吗? I could not find any docs on how to change the mongodb port in a spring boot project once compiled into a JAR.
编译成JAR后,我找不到任何有关如何在Spring Boot项目中更改mongodb端口的文档。
像这样做,
--spring.data.mongodb.port=27018
您可以尝试以下方法:
java -jar spring-5.jar --spring.data.mongodb.port=27018
There're many ways to overwrite the configure in the jar package. 有很多方法可以覆盖jar包中的配置。 Here are some common ways, try one of them:
以下是一些常用方法,请尝试其中一种:
application.properties
on your work directory. application.properties
。 java -Dspring.data.mongodb.port=27018 -jar the.jar
java -Dspring.data.mongodb.port=27018 -jar the.jar
jar -jar the.jar --spring.data.mongodb.port=27018
. jar -jar the.jar --spring.data.mongodb.port=27018
。 Don't forget to pass the args
from main()
to SpringApplication.run
. args
从main()
传递给SpringApplication.run
。 See https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html for more information 有关更多信息,请参见https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.