问题描述
我现在正在探索 Spring Boot 的可能性,我正在陷入了轻微的僵局.我希望能够同时运行两个 Spring Boot 应用程序,都在同一台服务器上,但路径不同(一个部署在 /
上,另一个部署在 /another-path代码>).
I'm exploring the possibilities of Spring Boot right now, and I'm at a slight impasse. I want to be able to run two Spring Boot applications at once, both on the same server, but at different paths (one deploys on /
, the other deploys at /another-path
).
因为这是在 Spring Boot 中运行的嵌入式 Tomcat 实例,所以没有可供我更改的配置文件.
Because this is an embedded Tomcat instance running within Spring Boot, there's no configuration files available for me to change.
有没有标准的方法来做到这一点?它可能吗?
Is there a standard way to do this? Is it possible?
推荐答案
Spring Boot 带有一些预构建的属性支持.如果您创建一个 application.properties 文件,您可以包括:
Spring Boot comes with some pre-built property support. If you create an application.properties file, you can include:
server.port=<another port>
server.address=<another IP address>
server.sessionTimeout=<another timeout setting>
server.contextPath=/your-other-path
这可以在与可运行 JAR 相邻的 application.properties 中,嵌入在 JAR 文件中,或者简单地作为 -Dserver.contextPath=/your-alt-path 应用strong> 与 java 命令.这些是级联的,这意味着您可以在 JAR 中嵌入一组默认值,使用本地 application.properties 文件覆盖,然后最后使用 -D 覆盖 application.properties选项.
This can be in application.properties adjacent to your runnable JAR, embedded inside the JAR file, or simply applied as a -Dserver.contextPath=/your-alt-path with the java command. These are cascading, meaning you can embed one set of defaults inside the JAR, override with a local application.properties file, and then finally override application.properties with the -D options.
这篇关于在 Spring Boot 中是否有自定义部署路径的标准方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!