1

I created a new grails app using below code

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

I modified ApplicationController and added namespace to it, It is as below:

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]
     } 
}

There is a index.gson file present under views/application/ Directory.

I run this setup using grails run-app and point my browser to http://localhost:8080

It throws following exeption:

<=======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

However if I modify controller code an use render, everything works fine.

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

Output of grails -v Grails Version: 4.0.2
JVM Version: 1.8.0_171 OS: macOS High Sierra

Ravikumar Sharma
  • 3,678
  • 5
  • 36
  • 59

1 Answers1

0

See Selecting Views For Namespaced Controllers

The correct path for the namespaced view should be:

grails-app/views/v1/application/index.gson
erichelgeson
  • 2,310
  • 1
  • 16
  • 24