Я создал новое приложение 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