title: How to enable controller parameter validation for standalone MockMvc
body: <p>Controller</p>
  <pre><code>@RestController
  @Validated
  class MyController {
  
      @GetMapping(&quot;/foo&quot;)
      public String unwrapped(@Min(1) @RequestParam(&quot;param&quot;) int param) {
          return Integer.toString(param);
      }
  
      @GetMapping(&quot;/bar&quot;)
      public String wrapped(@ModelAttribute @Valid Wrapper bean) {
          return Integer.toString(bean.param);
      }
  
      static class Wrapper {
  
          @Min(1)
          int param;
  
          public void setParam(final int param) {
              this.param = param;
          }
      }
  }
  </code></pre>
  <p>Test</p>
  <pre><code>public class MyControllerTest {
  
      MyController controller = new MyController();
      MockMvc mockMvc = MockMvcBuilders
              .standaloneSetup(this.controller)
              .build();
  
      @Test // fails
      public void unwrapped() throws Exception {
          this.mockMvc.perform(get(&quot;/foo&quot;)
                  .param(&quot;param&quot;, &quot;0&quot;))
                  .andExpect(status().isBadRequest());
      }
  
      @Test // passes
      public void wrapped() throws Exception {
          this.mockMvc.perform(get(&quot;/bar&quot;)
                  .param(&quot;param&quot;, &quot;0&quot;))
                  .andExpect(status().isBadRequest());
      }
  }
  </code></pre>
  <p>To enable (unwrapped) method parameter validation in spring the controller has to be annotated with <code>@Validated</code> and the <code>MethodValidationPostProcessor</code> must be added to the context.<br />
  Is it possible to add the <code>MethodValidationPostProcessor</code> bean to the standalone setup ?<br />
  The question might be reduced to how to add a <code>BeanPostProcessor</code> to a standalone MockMvc setup ?</p>