我正在使用 IntelliJ、Maven、Spring-boot。
我正在尝试使用 VM 选项(第三个选项卡(运行程序),取消选中“使用项目设置”)将端口设置为 8001,如堆栈溢出的许多答案中给出的那样。这是我尝试过的 2 个选项。
-Dmaven.tomcat.port=8001
-Dserver.port=8001
但是 tomcat 服务器在默认的 8080 端口上启动。
但是,如果我在 application.properties 上声明端口:
server.port=8001
效果很好。如何使用 VM 选项运行它。我不想以编程方式提供它或在 application.properties 中配置。
我已经尝试过: Spring Boot - how to configure port
还有其他一些。
请注意,我使用 intelliJ 上给出的调试/运行按钮运行
控制台显示命令为:
/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/bin/java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:56655,suspend=y,server=n -Dmaven.multiModuleProjectDirectory=/Users/barora/gitHub/microservice/currency-exchange-service -Dserver.port=8001 "-Dmaven.home=/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3" "-Dclassworlds.conf=/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3/bin/m2.conf" -javaagent:/Users/barora/Library/Caches/IntelliJIdea2017.3/captureAgent/debugger-agent.jar=/private/var/folders/g5/6nfrnqnj2tz_z0q8h9ckhbqjwmtnv2/T/capture127.props -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3/boot/plexus-classworlds-2.5.2.jar:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar" org.codehaus.classworlds.Launcher -Didea.version=2017.3.4 spring-boot:run
在哪里可以看到-Dserver.port=8001
但是它从 8080 开始:
2018-03-23 00:10:09.092 INFO 48261 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
最佳答案
好吧,这是一个老问题,但这是我在谷歌中得到的第一个结果。这就是我所做的,基于https://stackoverflow.com/a/37215726/1922026中的答案。 :
我没有使用-Dserver.port=8090
,而是使用-Dspring-boot.run.jvmArguments='-Dserver.port=8090'
。
请注意,此参数仅在 fork=true 时有效: https://github.com/spring-projects/spring-boot/issues/7588
关于java - Spring Boot 应用程序不支持服务器端口的 VM 选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49443386/