Spring 3.0 inject files as resources

Randomize picture Randomize · Sep 20, 2011 · Viewed 42.8k times · Source

In my Spring 3.0 app, I have some resources in /WEB-INF/dir. At runtime I need some of them as an InputStream (or some other type). How can I retrieve them? Is it possible to inject them as a normal Resource?

Answer

Nikita Koksharov picture Nikita Koksharov · Mar 25, 2014

Here is an easiest way to do it via annotation:

import org.springframework.core.io.Resource;

@Value("classpath:<path to file>")
private Resource cert;