I have configured spring boot to load Jersey as a filter.
I have set my Jersey property to allow static content:
I have read in spring boot that I can put my content inside my resources dir, under directories named 'static', 'public' folders. Yet, I can never reach my index.html page. The only way I have gotten this to work is to create a webapp dir under src/main and put my index.html file in there. I am deploying the app as a jar.
I have tried to access the page with following urls:
http://localhost:8080/app/index.html <-- only works with webapp dir
http://localhost:8080/app/static/index.html
http://localhost:8080/index.html
I am using spring-boot-starter-jersey 1.3.2-Release
spring-boot-starter-jersey on its own isn't sufficient to switch on Spring Boot's support for serving static resources as it requires Spring MVC to be on the classpath. What other dependencies do you have? A dependency on spring-boot-starter-web is probably the easiest way to add what's needed.
I added spring-boot-starter-web to my pom as as dependency, created a static folder under resources and put in a new file, test.txt
I hit http://localhost:8080/app/test.txt and it still was not able to find resource.
Unless you have changed the default configuration, you don't need /app in the URL. If that's not it, can you please share a small sample that reproduces the problem?
I created a sample app for you.
https://github.com/patrickjamesbarry/JerseyStaticResourceProblem
http://localhost:8080/demo/hello <-- prints hello on screen
http://localhost:8080/demo/test.txt <-file not found
You are missing a dependency on spring-boot-starter-web. Once that has been added it works for me.
I had that in my original project but was excluding the spring mvc dependency. Turns out, that was the last missing piece. Thanks!
Won't there be any conflicts if we use "springboot-starter-web" as well as "springboot-starter-jersey" in the same project?
I ask this question because for "springboot-starter-jersey" - I see the following description:
"An alternative to springboot-starter-web".
It's a bit more subtle than can be covered in a short description but there won't be a conflict. It's an alternative in the sense of using JAX-RS vs Spring MVC to build a REST API. However, even if you use Jersey, you still need Spring MVC if you want to use Actuator's HTTP endpoints.
Thank you for the quick answer.
If I assume the following, is it correct?
(1) Jersey cannot serve static content in spring boot environment (I don't know why :-( ).
(2) So Jersey is set up only as a filter rather than a servlet.
(3) After Jersey finishes processing, you need a servlet to serve static content.
(4) For this, you include Spring MVC.
(5) Even if Spring MVC is around it has to wait in the background in vain, since the Jersey 'filter' is going to process every request.
@jot-hub Issues, particularly ones that are closed, aren't the best place for a discussion. We use Gitter if you'd like to join us there. Alternatively, you could post a question on Stack Overflow.
Most helpful comment
You are missing a dependency on
spring-boot-starter-web. Once that has been added it works for me.