我如何使用Spring引导服务位于的Dropbox文件夹静态内容? [英] How do I use Spring Boot to serve static content located in Dropbox folder?

查看:179
本文介绍了我如何使用Spring引导服务位于的Dropbox文件夹静态内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个春天启动的Web应用程序,我想成为位于共享的Dropbox目录在我的Linode VPS(〜/ Dropbox的/图片)的静态内容。我读过春季开机就会自动从服务的静态内容

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/",

但当然我的Dropbox目录不在类路径上。

but of course my Dropbox directory is not on the classpath.

虽然我可以配置Apache服务于我的Dropbox文件夹中的图片,我想利用Spring Security的优势来限制身份验证的用户静态内容的访问。

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.

推荐答案

您可以添加自己的静态资源处理程序(它覆盖缺省的),例如

You can add your own static resource handler (it overwrites the default), e.g.

@Configuration
public class StaticResourceConfiguration extends WebMvcConfigurerAdapter {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("file:/path/to/my/dropbox/");
    }
}

有关于这<一一些文档href=\"https://github.com/spring-projects/spring-boot/blob/master/docs/howto.md#serve-static-content\">Spring引导,但它实际上只是一个香草Spring MVC的功能。

There is some documentation about this in Spring Boot, but it's really just a vanilla Spring MVC feature.

这篇关于我如何使用Spring引导服务位于的Dropbox文件夹静态内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆