Mikayil Abdullayev
Mikayil Abdullayev

Reputation: 12367

How to serve static content in spring boot when servlet path is defined in config

I've noticed when specifying servlet path, serving static content doesn't work out of the box. In fact, I haven't been able to get it to work in any way. Here's a part of my application.properties file:

server.servlet.context-path=/online
spring.mvc.servlet.path=/app

If I comment out spring.mvc.servlet.path=/app then I am able to access the styles.css file that's under the resources/static folder when I hit the url localhost:8080/online/styles.css. But with that config in place, the app throws 404 error. The DispathcherServlet does not handle that request for sure, which AFAIK is the expected behavior. If ResourceHttpRequestHandler class is the one to handle it, then its handleRequest method misses the request. Any ideas as to what should be done?

Upvotes: 1

Views: 299

Answers (1)

balee
balee

Reputation: 173

ResourceHttpRequestHandler is also affected by changing spring.mvc.servlet.path, therefore the css will be served as localhost:8080/online/app/styles.css

Upvotes: 1

Related Questions