title: Spring MVC 3.0: How to validate path variable that is global to all request mappings efficiently?
body: <p>I'm trying to get my feet wet with Spring MVC 3.0, and while I can get it to work, I can't seem to handle this particular scenario efficiently.</p>
  
  <p>I have a controller with that handles "/{studyName}/module" prefix, and it looks something like this:-</p>
  
  <pre><code>@Controller
  @RequestMapping(value = "/{studyName}/module")
  public class ModuleController {
  
      @RequestMapping(...)
      public ModelAndView getA(@PathVariable String studyName, ...) {
          if (!validStudy(studyName)) { return bad request; }
          ...
      }
  
      @RequestMapping(...)
      public ModelAndView getB(@PathVariable String studyName, ...) {
          if (!validStudy(studyName)) { return bad request; }
          ...
      }
  
      @RequestMapping(...)
      public ModelAndView getC(@PathVariable String studyName, ...) {
          if (!validStudy(studyName)) { return bad request; }
          ...
      }
  
      @RequestMapping(...)
      public ModelAndView getD(@PathVariable String studyName, ...) {
          if (!validStudy(studyName)) { return bad request; }
          ...
      }
  }
  </code></pre>
  
  <p>The problem with this code is, I have the studyName validation scattered all over the methods and possibly in other Controllers' methods too. Is there a way I can perform validation on studyName path variable all in one spot without using something like AOP? How do you handle validation like this?</p>
  
  <p>Thanks.</p>