【问题标题】:server.servlet.context-path is not working over AWS enviromentserver.servlet.context-path 在 AWS 环境中不起作用
【发布时间】:2020-06-30 04:58:22
【问题描述】:

我刚刚在 AWS 弹性 beanstack 上托管了我的 springboot 应用程序 (WAR),但发现了一个奇怪的问题

server.servlet.context-path= /app-name/api/v0

这在 localhost 上运行得非常好,但是在通过 aws 部署后它不起作用,但是所有 API 都在没有来自 AWS 的上下文路径的情况下工作:

例子:

http://awsaddress.com/login  -> its working, but it should like 

 http://awsaddress.com/app-name/api/v0/login  -> its not working

【问题讨论】:

  • 检查您是否在 aws 上使用了不同的 spring 配置文件,如果是,请确保 servlet 上下文路径不会被该配置文件覆盖。尝试在部署时将 servlet contxt 作为命令行参数提供,以确保它不依赖于环境。
  • 我暂时没有使用任何配置文件,只有 db 详细信息和 apringboot 中 application.properties 文件中的上下文路径,如果您需要其他任何东西,请告诉我
  • 由于您使用的是弹性 bean 堆栈,请确保添加的环境变量中没有指定 servlet 上下文路径。另外,您是在外部 tomcat 中部署,还是只是使用战争或其他一些原因,例如因为您使用的是 jsp?
  • server.servlet.context-path= ${BRAINY_CONTEXT_PATH:/brainy/api/v0} 这是属性文件中的条目,请看截图,我在aws环境中也设置了相同的,我我没有使用外部 tomcat 之类的,只是在 AWS 弹性 beanstack 中上传了 WAR 文件

标签: amazon-web-services spring-boot amazon-elastic-beanstalk


【解决方案1】:

我知道这个帖子很老了,但我遇到了同样的问题。 就我而言,解决方案是在 application.properties 中添加以下行:

server.contextPath = /artifactId
server.servlet.contextPath = /artifactId

【讨论】:

    猜你喜欢
    • 2020-06-25
    • 2012-11-07
    • 2013-07-13
    • 1970-01-01
    • 1970-01-01
    • 2015-04-30
    • 2019-01-04
    • 2015-10-02
    • 1970-01-01
    相关资源
    最近更新 更多