5

I wanted my Grails 3.1.5 app to serve both JSON data using the *.gson format AND, for some pages/URLs I wanted to continue to use GSPs.

I built an app using the rest-api profile. Then I copied over controllers and views from an other app that I'd built using the web-api.

In doing so, and to be consistent, I also moved index.gson to a different location.

Now I get a:

Could not resolve view with name 'index' in servlet with name 'grailsDispatcherServlet'

Started digging into the viewResolvers that are available in the 3.1.5 code base. It is possible that the rest-api profile configures a viewResolver to look for *.gson files in a certain location.

Is there anyway to configure maybe a CompositeViewResolver that looks for both the views, *.gson and *.gsps?

If so, how can I do this?

Thanks!

Pankaj Tandon
  • 151
  • 1
  • 6
  • When you build from the rest-api profile, part of that profile definition is the elimination of most of the UI support - API's typically don't render UI, so the profile drops support to reduce file size. Might be less work if you start with a normal web app, and introduce the JSON responses/.gson format support for the API portions. – railsdog Apr 25 '16 at 11:28

1 Answers1

5

I've managed to resolve this issue by adding this plugin to build.gradle:

compile 'org.grails:grails-plugin-gsp'

and with both

profile 'org.grails.profiles:web'
profile 'org.grails.profiles:rest-api'

and apply plugins

apply plugin: 'org.grails.grails-web'
apply plugin: 'org.grails.grails-gsp'
apply plugin: 'org.grails.plugins.views-json'

Apparently, they remove it when you're using REST profile, to reduce overhead, as you rarely render HTML on REST service side.

Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96
Jezdimir Lončar
  • 433
  • 4
  • 14
  • 3
    Thanks, very useful, but since GRAILS 3.3 it is not enough, you need also `compile "org.grails.plugins:gsp:3.3.0.RC1"` in your build.gradle file instead of __org.grails:grails-plugin-gsp__ dependency, as it is said in [Official GRAILS documentation](https://gsp.grails.org/latest/guide/index.html#tagsAsMethodCalls). – Stefano Scarpanti Jul 03 '17 at 16:03