0

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?

1
  • @VikasVats Reverted thoroughly pointless edit. Commented Dec 10, 2015 at 12:30

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

You don't need Spring to serve static content. Tomcat will already do it by default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.