views:

117

answers:

1

What is the best way to have every request be sent to a single ViewResolver - specifically in this case a JsonView?

Was thinking this:

<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
    <property name="prefix" value="*" />
</bean>

but, is there something better/easier?

A: 

You've misunderstood what a ViewResolver is for. They're not there to service requests (that's what controllers are for), they're there to turn view names (as returned by the controller) into views (e.g. JSPs). The prefix and suffix properties are used to assemble the path to the view.

If you could describe what problem you're trying to solve, we can show you how.

skaffman
I am creating a rest endpoint that will return a Json response for a success/error giving details on what happened during the request. In this case, do I even need to set up a viewResolver? or do I just have the controller method return a JsonView?
wuntee
@wuntee: Sounds like you have no use for a `ViewResolver`, just return a `View` directly from the controller.
skaffman