Home > extjs4, spring-roo > Setting up ContentNegotioationViewResolver for using json with spring roo.

Setting up ContentNegotioationViewResolver for using json with spring roo.

I want to make a controller, that supports crud via json. I will use it against an extjs4 data store.
The controllers that spring roo generates, can not be used for this, so I will make a rest controller by hand.

First I will use ContentNegotioationViewResolver to resolve the view, based on extensions. Resolving based on accept-header is more risky since there is not a consistent behavior among the different browsers.

This is the setup:

    <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
        <property name="mediaTypes">
                <entry key="json" value="application/json"/>
        <property name="viewResolvers">
                <bean class="org.springframework.web.servlet.view.BeanNameViewResolver"/>
                <bean class="org.springframework.web.servlet.view.UrlBasedViewResolver" id="tilesViewResolver">
                    <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
        <property name="defaultViews">
                <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
        <!--<property name="ignoreAcceptHeader" value="true" />-->

Make sure MappingJackson is in the class path. And ignoreAcceptHeader should not be set to true if you still want the roo-generated web pages to work – they use accept-header.

Now we are ready to make the json rest controller.

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: