Spring:在上下文根之外提供静态资源 [英] Spring : serving static resources outside context root

查看:24
本文介绍了Spring:在上下文根之外提供静态资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在网络应用程序中,我需要提供位于应用程序上下文目录之外的静态内容(图像).整体应用架构需要我使用Tomcat来执行.我想我可以从 Spring 的 <mvc:resources> 中受益,以配置应用程序 URL 和目录内容之间的映射.但 AFAIK 它的 mapping 属性仅处理上下文相关或类路径映射.因此,我想使用什么:

in a web app, I need to serve static contents (images) located outside the application context directory. The overall application architecture requires me to use Tomcat to perform this. I thought I could benefit from Spring's <mvc:resources> to configure a mapping between application URLs and directory contents. But AFAIK it's mapping attribute only handles context relative, or classpath mappings. Hence, what I'd like to use :

<mvc:resources location="/images/**" mapping="/absolute/path/to/image/dir"/>

不起作用.由于我宁愿避免编写一个简单的文件传输 servlet,如果有人能就现有的基于 Spring 的解决方案/变通方法给我一些建议,我会很高兴.

doesn't work. As I'd rather avoid writing a simple file transfer servlet, I'd be glad if anyone could give me some pointers on existing Spring based solutions/workarounds.

非常感谢.

荷马

推荐答案

可以从外部提供资源,需要使用通常的 Spring资源路径语法:

<mvc:resources> can serve resources from the outside, you need to use the usual Spring resource path syntax:

<mvc:resources mapping="/images/**" location="file:/absolute/path/to/image/dir/"/> 

这篇关于Spring:在上下文根之外提供静态资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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