Spring:在上下文根之外提供静态资源
在网络应用程序中,我需要提供位于应用程序上下文目录之外的静态内容(图像)。整个应用程序架构要求我使用 Tomcat 来执行此操作。我认为我可以受益于 Spring 的
来配置应用程序 URL 和目录内容之间的映射。但据我所知,它的 mapping
属性仅处理上下文相关或类路径映射。因此,我想使用的 :
<mvc:resources location="/images/**" mapping="/absolute/path/to/image/dir"/>
不起作用。因为我宁愿避免编写一个简单的文件传输 servlet,所以如果有人能给我一些关于现有的基于 Spring 的解决方案/解决方法的指示,我会很高兴。
非常感谢。
荷马
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"/>
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.
Many thanks.
Homer
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以从外部提供资源,需要使用常用的Spring 资源路径语法:<mvc:resources>
can serve resources from the outside, you need to use the usual Spring resource path syntax:还有一个更简单的更正,
代码应该是
你注意到差异了吗?
您需要将“/”放在绝对路径的末尾。
或者你可以使用java配置
它对我有用。
There is one more simple correction
the code should be
<mvc:resources mapping="/images/**" location="file:/absolute/path/to/image/dir/"/>
Did you notice the difference ?
You need to put '/' at the end of the absolute path.
or you can use the java configuration
Its working for me.