Tuesday, March 24, 2015

Spring REST and wildcard url-pattern in web.xml

The wildcard url-pattern '/api/*' in web.xml doesn't work with Spring REST @RequestMapping's absolute path like '/api/customers'.
@RequestMapping's relative path without any leading slash like 'customers' does work.

In web.xml
  <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/api/*</url-pattern>
    <url-pattern>*.htm</url-pattern>
  </servlet-mapping>

In your java source code
 @RequestMapping( "customers" )

Now you can use the URL 'http://myserver.com/api/customers'.