java - 使用 Spring 框架,在创建新文件夹后更新文件夹映射

标签 java spring mapping directory

我的应用程序使用 Spring 框架,它管理图像的上传。对于每个图像,我会创建一个文件夹:

->webSite ->images/
                 ->img1/img1.jpg
                 ->img2/img2.jpg
after a new upload i will have
->webSite ->images/
                 ->img1/img1.jpg
                 ->img2/img2.jpg
                 ->img3/img3.jpg

不幸的是,当我部署该程序时,所有图像都可以立即访问,但上传后,新图像不是。(在前面的示例中,img1/img1.jpg 可以,img2/img2.jpg 可以,但是img3/img3.jpg 错误 404 )

如果我再次部署,图像 img3.jpg 现在可用。

有人知道如何在运行时刷新文件夹的映射吗?

为了映射初始文件夹图像,我仅设置了 web.xml:

        <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>/images/*</url-pattern>
        </servlet-mapping>

最佳答案

尝试对资源使用特殊的spring配置而不是特殊的serlvet:

<mvc:resources location="/, classpath:/META-INF/web-resources/" mapping="/resources/**"/>

将此行放入您的 servlet-context.xml

关于java - 使用 Spring 框架,在创建新文件夹后更新文件夹映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18362727/

相关文章:

java - 列表到字符串。安卓

java - Spring junit Autowiring 自定义类必须有构造函数本身吗?

java - liferay 7.2 中的 Spring Autowiring 注释

Hibernate:映射 3 个表

c# - 类映射错误 : 'T' must be a non-abstract type with a public parameterless constructor

java - 未报告的异常 java.io.IOException

java - HTML 换行标记在文本中可见,而不是换行

java - 将变量声明为 Enum<EnumType> 和 EnumType 之间的区别

spring - MockMvc 返回 null 而不是对象

java - Orika 是否支持来自 java.util.Set 的映射?