6

I am getting a HTTP 404 error when trying to serve index.html ( located under main/resources/static) from a spring boot app. However if I remove the Jersey based JAX-RS class from the project, then http://localhost:8080/index.html works fine.

The following is main class

@SpringBootApplication
public class BootWebApplication {

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

I am not sure if I am missing something here.

Thanks

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
Rocky
  • 365
  • 1
  • 5
  • 15
  • @emoleumassi Can you please elaborate on the compatibility problems? We (the Spring Boot team) aren't aware of any. – Andy Wilkinson Feb 03 '16 at 09:58
  • @Andy Wilkinson i already had bad experience with Spring boot and jersey. Check my posts for more explanation: http://stackoverflow.com/questions/33026968/spring-boot-org-springframework-beans-factory-beancreationexception-could-not-a and http://stackoverflow.com/questions/33000931/spring-boot-cannot-access-some-controllers – emoleumassi Feb 03 '16 at 12:55

1 Answers1

10

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.properties - spring.jersey.applicationPath.

Community
  • 1
  • 1
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720