Search code examples
springgrailsurl-mapping

Grails: Setting URL mapping priorities


I sometimes come across a situation where I'm trying to set URLMappings as such:

    /** -> ContentController
    /static/$image/$imageNumber -> ResourcesController

Then when I visit /static/image/13 it will often hit the /** instead of the

/static/*/*
How do I tell Spring / Grails to rather try and match the other one first?


Solution

  • Turns out that Grails will go from more specific to least specific, as long as:

    1. You don't have syntax errors in your URLMappings and
    2. Sometimes you need to restart grails for it to correctly take effect.

      "/other-test/$testname" { // Fired for "/other-test/hi-there/"
          controller="test"
      }
      
      "/**" { // fired for "/something-else"
          controller="test"
      }