【问题标题】:server.port and server.context-path not taking effect when deployed to tomcat部署到tomcat时server.port和server.context-path不生效
【发布时间】:2018-03-23 22:17:25
【问题描述】:

我有一个 springboot 应用程序,我想在 tomcat 中部署它。我按照说明here 我在 src/main/resources 中有 application.properties 文件,其中包含以下条目

server.context-path=/mycontext
server.port=9000

我可以看到这些属性是从执行器 url 加载的。

applicationConfig: [classpath:application.properties]": {
"server.port": "9000",
"server.context-path": "/mycontext"}

当我将它作为可执行 jar 运行时,它工作正常,但是当我部署到 tomcat 时,它仍然侦听 8080 端口并且上下文值没有更新,而是回退到应用程序文件夹名称。如果我错过了什么,请告诉我。提前致谢。

【问题讨论】:

  • 你在外部部署了它?
  • 是构建为战争并部署到 tomcat

标签: java spring spring-mvc tomcat spring-boot


【解决方案1】:

默认情况下,

  • Tomcat 监听 8080 端口,当你在 tomcat 中部署 war 时,它也会监听 8080 端口,这不能改变 tomcat 的监听端口。

  • application.properties 文件是你的 springboot 项目的配置,但它不适用于 tomcat。

  • springboot 项目中有一个内置的tomcat。当您在application.properties 文件中更改其配置时,它会自动更改内置tomcat 的配置。

如果您想将项目部署到 tomcat 并在端口 9000 上侦听,则需要更改 tomcat 的配置文件(将侦听端口从8080 更改为9000)。

注意:Springboot 项目为我们提供了智能部署技术,只需要一个命令。如果使用 springboot 项目,则无需使用另一个 tomcat 进行部署。

【讨论】:

  • here 得到答案。看起来有 server.* 配置属性仅适用于嵌入式容器
【解决方案2】:

server.* application.properties 中的配置值仅适用于嵌入式服务器。外部容器默认使用应用程序名称作为上下文根,如 here

【讨论】:

    猜你喜欢
    • 2016-05-31
    • 2018-02-27
    • 2013-03-03
    • 2016-10-31
    • 2014-11-30
    • 2020-02-09
    • 1970-01-01
    • 2015-11-15
    • 2020-07-14
    相关资源
    最近更新 更多