You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Grails 5本地运行URL无应用名称,求变更原因及恢复方法

Grails 5.3.2 运行URL无应用名的原因及恢复方法

变更原因

Grails 5 底层基于 Spring Boot 2.x,而 Spring Boot 2.x 开始默认将嵌入式服务器的上下文路径设为根路径(/)。Grails 3.3.x 及更早版本默认会把应用名称作为上下文路径,Grails 5 跟随了 Spring Boot 的这一默认行为变更,所以通过 grails run-app 运行时,URL 不再自动附加应用名称。

恢复原有行为的方法

你可以通过以下两种方式恢复带应用名的上下文路径:

1. 命令行临时指定

运行启动命令时添加参数:

grails run-app -Dserver.servlet.context-path=/myappname

2. 配置文件永久设置

修改项目的配置文件,根据你使用的格式选择:

  • application.yml:
    server:
      servlet:
        context-path: /myappname
    
  • application.groovy:
    server.servlet.context-path = "/myappname"
    

修改后重启应用,即可通过 http://localhost:8080/myappname 访问。

内容的提问来源于stack exchange,提问作者Shastings

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 10:58:13