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

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

问题描述

我有一个 Spring Boot Web 应用程序,我想在我的 Linode VPS (~/Dropbox/images) 上提供位于共享 Dropbox 目录中的静态内容.我读过 Spring Boot 将自动提供来自

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/");
    }
}

Spring Boot,但它实际上只是一个普通的 Spring MVC 特性.

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

此外,从 spring boot 1.2(我认为)开始,您可以简单地设置 spring.resources.staticLocations.

Also since spring boot 1.2 (I think) you can simply set spring.resources.staticLocations.

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

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