title: Spring boot REST controller POST request handling
body: <p>Using Spring Boot (v1.2.6.RELEASE), I need to accept  POST requests for the Controller methods.</p>
  
  <pre><code>@RestController
  @RequestMapping(value = "/myWebApp/signup")
  public class RegController {
  
      @RequestMapping(value = "/registerFamily", method = { RequestMethod.POST  }, headers = {"Content-type=application/json"})
  @ResponseBody
  public FamilylResponse registerFamily(@RequestBody @Valid FamilyRequest familyRequest){
  </code></pre>
  
  <p>...
      }</p>
  
  <p>When I send <strong>POST</strong> request from REST clients from Chrome/mozilla,the response comes as follows:</p>
  
  <pre><code>{"timestamp":1446008095543,"status":405,"error":"Method Not Allowed","exception":"org.springframework.web.HttpRequestMethodNotSupportedException","message":"Request method 'POST' not supported","path":"/myWebApp/signup/registerFamily"}
  
  ...
  </code></pre>
  
  <p>The stack trace is as follows:</p>
  
  <pre><code>  org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported
  at org.springframework.web.servlet.support.WebContentGenerator.checkAndPrepare(WebContentGenerator.java:273)
  at org.springframework.web.servlet.support.WebContentGenerator.checkAndPrepare(WebContentGenerator.java:251)
  at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.handleRequest(ResourceHttpRequestHandler.java:207)
  at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:51)
  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)  
  </code></pre>
  
  <p>Following the response of <a href="https://stackoverflow.com/questions/15588001/spring-not-accept-post-request-under-mvcresources-how-to-fix-that">Spring: not accept POST request under mvc:resources? how to fix that</a>,</p>
  
  <p>I think some other sub class of <strong>WebContentGenerator</strong>, like <strong>WebContentInterceptor</strong>, <strong>RequestMappingHandlerAdapter</strong>  should handle the requests for Controllers.</p>
  
  <p>Also while running Junit tests, I found that the <strong>RequestMappingHandlerAdapter</strong> is handling those requests for Controllers.</p>
  
  <p>But I'm yet to find how to configure this to accept POST requests as well?</p>
  
  <p>Any other better solution should be more than welcome.</p>
  
  <p><strong>EDIT</strong>:</p>
  
  <p><strong>Tomcat</strong> uses <strong>WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter</strong>(a subclass of WebMvcConfigurerAdapter)
   and </p>
  
  <p>WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter.<strong>addResourceHandlers</strong>(ResourceHandlerRegistry) does the following:</p>
  
  <p>o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]</p>
  
  <p>o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]</p>
  
  <p>In <strong>junit</strong>, I have added an empty concrete child class of WebMvcConfigurerAdapter.</p>
  
  <p>and WebMvcConfigurerAdapter.addResourceHandlers(ResourceHandlerRegistry) does nothing.</p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  public class WebAppContext extends WebMvcConfigurerAdapter {}
  
  @Configuration
  @Import({ WebAppContext.class })
  @PropertySource("classpath:application.properties")
  public class ExampleApplicationContext { }
  
  
  @RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(classes = {ExampleApplicationContext.class})
  @WebAppConfiguration
  public class RegControllerTest {  ... }   
  </code></pre>