Jasper Blues
Jasper Blues

Reputation: 28786

Tomcat Serve Static Files

Is it possible to serve static files from Tomcat? Would Tomcat do this efficiently? From memory, I believe the Java EE spec included a clause disallowing serving static files.

Eventually I'll need to integrate a CDN as well. Would using Tomcat prevent this?

Upvotes: 0

Views: 814

Answers (1)

JB Nizet
JB Nizet

Reputation: 692181

Is it possible to serve static files from Tomcat in a Spring Boot application?

Yes, of course. Opening the reference documentation and looking for "static" immediately leads to http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-spring-mvc-static-content, which explains how to do it.

Would Tomcat do this efficiently?

Yes. Probably a bit less efficiently than nginx or Apache would do it, but it shouldn't matter much. And if it matters, then you probably want a CDN.

From memory, I believe the Java EE spec included a clause disallowing serving static files.

No. Any file inside a war file, not under WEB-INF, is served as a static resource.

Eventually I'll need to integrate a CDN as well. Would using Tomcat prevent this?

Why would it. Using a CDN simply consists in using absolute paths to some resource on the web rather than using a path pointing to your web app. Tomcat doesn't care.

Upvotes: 2

Related Questions