Spring Boot and Jersey (JAX-RS) static files support

In Spring Boot support of Jersey provided by org.springframework.boot:spring-boot-starter-jersey Gradle dependency. When static files URL pattern matched with URLs which Jersey handles, additional configurations required for Spring Boot to serve static resources.

Note: We are using Gradle dependency management system, configuration for Maven will be similar.

Add Spring Boot web starter dependency

File : build.gradle (Snippet)

dependencies {
     compile 'org.springframework.boot:spring-boot-starter-web',
    testCompile 'org.springframework.boot:spring-boot-starter-test'

Add org.springframework.boot:spring-boot-starter-web to enable Spring Web application support. We need @SpringBootApplication on Spring Boot main application class or @EnableAutoConfiguration. With these annotation Spring Boot will auto configure serving of static content from /src/resources/static/ or /src/resources/public folders.

Unfortunately our Spring Boot server doesn’t serve static files as expected. It happens because of Jersey servlet, which is handling all http requests (/*) and doesn’t have clue about static files. If Jersey is only handling some http requests, for e.g. /api/* then this problem will not arise as long as static resources are not kept on /api/* path.

Jersey configuration

We have to make two Jersey configurations changes.

Use Filter to process request

Jersey can handle requests either using Servlet or using Filter. By default Servlet is used. Make following changes so Filter is used.

File: application.properties


User Filter forward 404

If Jersey doesn’t have clue (HTTP status code 404) about request, it should forward it for further processing.

File: JerseyConfig.java (snippet)

public class JerseyConfig extends ResourceConfig {

	 * In constructor we can define Jersey Resources & Other Components
	public JerseyConfig() {
		 * Jersey will automatically register class with @provider, @Component  by scanning
		 * these packages + nested packages
		packages("in.geekmj.resource", "in.geekmj.config");
		/* CustomTypeParamterConsumeResource auto scanned and register */
		property(ServletProperties.FILTER\_FORWARD\_ON\_404, true);

property(ServletProperties.FILTER_FORWARD_ON_404, true); will forward (to other Servlet or filters) all requests which Jersey can’t process (404).

Let say we have a file /src/resources/static/index.html, it accessible at https://:/index.html now.


  1. Official Jersey Documentation
  2. Spring Boot reference
  3. Download the Full Project
  4. Follow Project On Github