Skip to content

Instantly share code, notes, and snippets.

@ufuk
Last active July 11, 2017 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ufuk/9a02104320149099e30093ff57cc232f to your computer and use it in GitHub Desktop.
Save ufuk/9a02104320149099e30093ff57cc232f to your computer and use it in GitHub Desktop.
Getting and using a file from classpath with Spring's @ Value annotation.
package ...;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;
import java.io.InputStream;
@Service
public class SomeSpringBeanThatNeedsAResource {
@Value("classpath:/file.ext")
private Resource file;
... void someMethodThatIsUsingTheResource() {
InputStream inputStream = file.getInputStream()
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment