title: Validate format parameter via config in Spring MVC
body: <p>Here is my situation:</p>
  
  <p>I have my mvc-config.xml file for my web service set up to have JSON as the default media type. I also have favorParameter for the ContentNegotiatingViewResolver as true. Additionally, I have useNotAcceptableStatusCode as true so that not accepted formats will return a 406.</p>
  
  <p>My question is: Is there a way, in the config, to trigger the 406 status code when someone passes in an unacceptable format parameter (format=foo)? Or must that be done with code?</p>
  
  <p>Here is the config file:</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
      xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"&gt;
  
      &lt;bean
          class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"&gt;
          &lt;property name="mediaTypes"&gt;
              &lt;map&gt;
                  &lt;entry key="json" value="application/json" /&gt;
                  &lt;entry key="xml" value="application/xml" /&gt;
              &lt;/map&gt;
          &lt;/property&gt;
          &lt;property name="defaultViews"&gt;
              &lt;list&gt;
                  &lt;bean class="com.work.stuff.web.view.json.ExtendedMappingJacksonJsonView"&gt;
                      &lt;property name="objectMapper"&gt;
                          &lt;ref bean="JacksonObjectMapper" /&gt;
                      &lt;/property&gt;
                  &lt;/bean&gt;
                  &lt;bean class="org.springframework.web.servlet.view.xml.MarshallingView"&gt;
                      &lt;property name="marshaller"&gt;
                          &lt;ref bean="Jaxb2Marshaller" /&gt;
                      &lt;/property&gt;
                  &lt;/bean&gt;
              &lt;/list&gt;
          &lt;/property&gt;
          &lt;property name="defaultContentType" value="application/json" /&gt;
          &lt;property name="favorParameter" value="true" /&gt;
          &lt;property name="useNotAcceptableStatusCode" value="true" /&gt;
      &lt;/bean&gt;
  
      &lt;bean
          class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"&gt;
          &lt;property name="messageConverters"&gt;
              &lt;list&gt;
                  &lt;bean
                      class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"&gt;
                      &lt;property name="objectMapper"&gt;
                          &lt;ref bean="JacksonObjectMapper" /&gt;
                      &lt;/property&gt;
                  &lt;/bean&gt;
                  &lt;ref bean="marshallingHttpMessageConverter" /&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="marshallingHttpMessageConverter"
          class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter"&gt;
          &lt;property name="marshaller" ref="Jaxb2Marshaller" /&gt;
          &lt;property name="unmarshaller" ref="Jaxb2Marshaller" /&gt;
      &lt;/bean&gt;
      &lt;bean id="JacksonObjectMapper" class="org.codehaus.jackson.map.ObjectMapper" /&gt;
      &lt;bean id="JacksonSerializationConfig" class="org.codehaus.jackson.map.SerializationConfig"
          factory-bean="JacksonObjectMapper" factory-method="getSerializationConfig" /&gt;
      &lt;bean
          class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"&gt;
          &lt;property name="targetObject" ref="JacksonSerializationConfig" /&gt;
          &lt;property name="targetMethod" value="setSerializationInclusion" /&gt;
          &lt;property name="arguments"&gt;
              &lt;list&gt;
                  &lt;value type="org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion"&gt;NON_NULL&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
      &lt;bean id="Jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"&gt;
          &lt;property name="classesToBeBound"&gt;
              &lt;list&gt;
                  &lt;value&gt;com.work.stuff.Concepts&lt;/value&gt;
                  &lt;value&gt;com.work.stuff.Concept&lt;/value&gt;
                  &lt;value&gt;com.work.stuff.Terms&lt;/value&gt;
                  &lt;value&gt;com.work.stuff.Term&lt;/value&gt;
                  &lt;value&gt;com.work.stuff.Namespaces&lt;/value&gt;
                  &lt;value&gt;com.work.stuff.Namespace&lt;/value&gt;
                  &lt;value&gt;com.work.stuff.Subsets&lt;/value&gt;
                  &lt;value&gt;com.work.stuff.Subset&lt;/value&gt;
                  &lt;value&gt;com.work.stuff.Associations&lt;/value&gt;
                  &lt;value&gt;com.work.stuff.Association&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>