title: Spring MVC - How to post to any URL?
body: <p>I want to post <code>http://localhost:8080/TestSpringMVCAndStuff/hi/zzz?input=abcdef&amp;crap=1234567</code> to a <code>/hi/*</code> address.</p>
  
  <p>However, I keep getting 404 error.</p>
  
  <p>Is there a way to make this work?</p>
  
  <p>WebAppInitializer</p>
  
  <pre><code>public class WebAppInitializer implements WebApplicationInitializer {
  
      @Override
      public void onStartup(ServletContext container) throws ServletException {
          AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
          ctx.register(WebAppConfiguration.class);
          ctx.setServletContext(container);
          {
              ServletRegistration.Dynamic servlet = container.addServlet(
                      "dispatcherHi", new DispatcherServlet(ctx));
  
              servlet.setLoadOnStartup(1);
              servlet.addMapping("/hi/*");
          }
      }
  }
  </code></pre>
  
  <p>AnotherController</p>
  
  <pre><code>@Controller
  @RequestMapping("/hi/*")
  public class AnotherController {
      @Autowired(required=false)
      @RequestMapping(method = RequestMethod.POST)
      public void processRequest(HttpServletRequest request, HttpServletResponse response) {
  
          try{
              response.getOutputStream().write("hello world!".getBytes());
          }
          catch(Exception e){
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>WebAppConfiguration</p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  @ComponentScan(basePackages = "com.test.springmvc")
  public class WebAppConfiguration extends WebMvcConfigurerAdapter {
  
      /*
       * Configure View Resolver 
       */
      @Bean
      public ViewResolver viewResolver() {
          InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
          viewResolver.setViewClass(JstlView.class);
          viewResolver.setPrefix("/WEB-INF/views/");
          viewResolver.setSuffix(".jsp");
          return viewResolver;
      }
  
      /*
       * Configure MessageSource to provide internationalized messages
       * 
       */
  
      @Bean
      public MessageSource messageSource() {
          ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
          messageSource.setBasename("messages");
          return messageSource;
      }
  
      /*
       * Configure ResourceHandlers to serve static resources like CSS/ Javascript etc...
       * 
       */
      @Override
      public void addResourceHandlers(ResourceHandlerRegistry registry) {
          registry.addResourceHandler("/static/**").addResourceLocations("/static/");
      }
  }
  </code></pre>