Spring:在上下文根外部提供静态资源 [英] Spring : serving static resources outside context root
问题描述
在Web应用程序中,我需要提供位于应用程序上下文目录之外的静态内容(图像).整个应用程序体系结构要求我使用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.
非常感谢.
荷马
推荐答案
<mvc:resources>
可以从外部提供资源,您需要使用通常的
<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屋!