圣杯 4.0.2.无法解析名称为 'index' 的 servlet 中具有名称'grailsDispatcherServlet'的视图



我使用以下代码创建了一个新的grails应用程序

grails create-app myapp --profile=rest-api

我修改了ApplicationController并添加了命名空间,如下所示:

class ApplicationController implements PluginManagerAware {
/** The Namespace for the version of the API, see http://docs.grails.org/latest/guide/REST.html#versioningResources */
static namespace = "v1"
GrailsApplication grailsApplication
GrailsPluginManager pluginManager
def index() {
[grailsApplication: grailsApplication, pluginManager: pluginManager]
} 
}

views/application/目录下存在一个index.gson文件。

我使用grails run-app运行此设置,并将浏览器指向http://localhost:8080

它抛出以下示例:

<=======2020-04-08 16:01:31.616 ERROR --- [nio-8080-exec-1] .a.c.c.C.[.[.[.[grailsDispatcherServlet] : Servlet.service() for servlet [grailsDispatcherServlet] in context with path [] threw exception [Could not resolve view with name 'index' in servlet with name 'grailsDispatcherServlet'] with root cause

然而,如果我修改控制器代码并使用render,一切都会正常工作。

render(view:'index',model: [grailsApplication: grailsApplication, pluginManager: pluginManager])

grails-v的输出Grails版本:4.0.2
JVM版本:1.8.0_171操作系统:macOS High Sierra

请参见为命名空间控制器选择视图

命名空间视图的正确路径应该是:

grails-app/views/v1/application/index.gson

相关内容

最新更新