Spring boot not serving static content when Jersey REST is included

The problem is the default setting of the Jersey servlet path, which defaults to /*. This hogs up all the requests, including request to the default servlet for static content. So the request is going to Jersey looking for the static content, and when it can’t find the resource within the Jersey application, it will send out a 404.

You have a couple options around this:

  1. Configure Jerse runtime as a filter (instead of as a servlet by default). See this post for how you can do that. Also with this option, you need to configure one of the ServletProperties to forward the 404s to the servlet container. You can use the property that configures Jersey to forward all request which results in a Jersey resource not being found, or the property that allows you to configure a regex pattern for requests to foward.

  2. You can simply change the Jersey servlet pattern to something else other than the default. The easiest way to do that is to annotate your ResourceConfig subclass with @ApplicationPath("/root-path"). Or you can configure it in your application.propertiesspring.jersey.applicationPath.

Leave a Comment