Last active
July 11, 2017 07:50
-
-
Save ufuk/9a02104320149099e30093ff57cc232f to your computer and use it in GitHub Desktop.
Getting and using a file from classpath with Spring's @ Value annotation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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