I have a Spring Boot web application, and I would like to serve static content located in a shared Dropbox directory on my Linode VPS (~/Dropbox/images). I've read that Spring Boot will automatically serve static content from
"classpath:/META-INF/resources/",
"classpath:/resources/",
"classpath:/static/",
"classpath:/public/",
but of course my Dropbox directory is not on the classpath.
Although I could configure Apache to serve the images in my Dropbox folder, I would like to take advantage of Spring Security to restrict access of the static content to authenticated users.
To serve from file system
I added
spring.resources.static-location=file:../frontend/build
inapplication.properties
index.html
is present in thebuild
folderUse can also add absolute path
spring.resources.static-location=file:/User/XYZ/Desktop/frontend/build
I think similarly you can try adding Dropbox folder path.
For the current Spring-Boot Version 1.5.3 the parameter is
spring.resources.static-locations
Update I configured
`spring.resources.static-locations=file:/opt/x/y/z/static``
and expected to get my index.html living in this folder when calling
http://<host>/index.html
This did not work. I had to include the folder name in the URL:
http://<host>/static/index.html
You can place your folder in the root of the ServletContext.
Then specify a relative or absolute path to this directory in application.yml:
The resources in this folder will be available (for downloading, for example) at:
I wanted to serve static content from c:/images
Adding this property worked for me:
I found the original value of the property in the Spring Boot Doc Appendix A
This will make c:/images/image.jpg to be accessible as http://localhost:8080/image.jpg
@Mark Schäfer
Never too late, but add a slash (
/
) after static:So
http://<host>/index.html
is now reachable.Note that WebMvcConfigurerAdapter is deprecated now (see WebMvcConfigurerAdapter). Due to Java 8 default methods, you only have to implement WebMvcConfigurer.