以下のコードを使用して新しい 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]
}
}
ディレクトリの下に存在するindex.gson
ファイルがありますviews/application/
。
を使用してこのセットアップを実行し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 OS: macOS High Sierra