【发布时间】:2020-09-03 19:44:51
【问题描述】:
我的情况很奇怪。我在 Spring Boot 和基于安全性的项目中的静态资源(图像、图标、css、js 等)在某些上下文路径上加载得很好,但在其他路径上不起作用。 例如下面的工作就好了:
http://localhost:8080/appUserProfile/1
但是为此,资源不会加载:
http://localhost:8080/appUserProfile/1/image
对于以上内容,我已经在我的 mvc 配置中尝试了以下所有方法:
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/appUserProfile**").addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS);
registry.addResourceHandler("/appUserProfile/**").addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS);
registry.addResourceHandler("/appUserProfile/**/**").addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS);
registry.addResourceHandler("/appUserProfile/*/**").addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS);
registry.addResourceHandler("/appUserProfile/*/*").addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS);
}
除上述之外,每当我遇到访问被拒绝时,都会发生同样的事情。 我的自定义 403 页面加载正常,但资源无法加载。
问题:
为什么它适用于 /appUserProfile/1 而不适用于 /appUserProfile/1/image?我在这里缺少什么和/或这里有什么问题?
如何在拒绝访问页面加载资源?这个非常特殊的页面是否需要这些相关或任何特殊配置?
这里是我完整的security 和mvcConfig 课程,以防上面提供的信息不够。
更新:
【问题讨论】:
标签: spring-boot spring-security thymeleaf