【发布时间】:2018-09-01 18:14:36
【问题描述】:
我正在使用 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)
【问题讨论】:
-
您是否尝试在 application.properties 文件中添加端口号?
-
文档中没有提到 -D 选项。但 --server.port=8001 是:docs.spring.io/spring-boot/docs/current/reference/html/… - 你能试试吗?
-
@wemu ,我试过了,它给了我:无法识别的选项:--server.port=8001 错误:无法创建 Java 虚拟机。错误:发生了致命异常。程序将退出。
-
@UditKumawat 阅读我的第 5、6 和 7 行。
-
这不起作用,因为您使用了错误的属性。例如,请参见此处的示例:docs.spring.io/spring-boot/docs/current/maven-plugin/examples/… - maven 插件文档状态:docs.spring.io/spring-boot/docs/current/maven-plugin/… - 用于运行目标的 jvmArguments 的用户属性是“spring-boot.run.jvmArguments” - 所以在命令行上使用 -D 选项: mvn spring-boot:run -Dspring-boot.run.jvmArguments="..." - 使用错误的参数名称时,您的选项不会被选中。
标签: java spring maven spring-boot intellij-idea