Spring boot does not serve static content when Jersey REST is enabled

I get an HTTP 404 error when trying to service index.html (located mainly / resource / static) from a spring boot application. However, if I remove the Jersey-based class from the JAX-RS, the project http: // localhost: 8080 / index.html works fine.

Below is the main class

@SpringBootApplication public class BootWebApplication { public static void main(String[] args) { SpringApplication.run(BootWebApplication.class, args); } } 

I'm not sure if something is missing here.

thanks

+6
source share
1 answer

The problem is the default setting for the Jersey servlet path, which defaults to /* . This causes all requests, including the default servlet request for static content. Thus, the request is sent to Jersey, which is looking for static content, and when it cannot find the resource in the Jersey application, it will send 404.

You have a couple of options:

  • Set Jerse runtime as a filter (and not as the default servlet). See this post for how you can do this. Also with this option you need to configure one of ServletProperties to forward 404s to the servlet container. You can use the property that configures Jersey to forward the entire request, because of which the Jersey resource was not found, or the property that allows you to configure the regular expression pattern for requests to the file.

  • You can simply change the Jersey servlet template to something other than the default. The easiest way to do this is to annotate your ResourceConfig subclass using @ApplicationPath("/root-path") . Or you can configure it in application.properties - spring.jersey.applicationPath .

+8
source

All Articles