我正在生产 Spring Boot Vaadin 项目。在此项目中,我在 /resources/META-INF/resources/icons(images) 中使用自定义图像和图标。我使用 nl.martijndwars 依赖项在我的项目中添加了推送通知。 在指南中,我需要将 sw.ts(Service Worker 文件,由 vaadin 生成)移动到前端文件夹。自从我完成后,我的一些自定义图标并不总是加载。 (405代码。不允许使用GET方法)
当我在本地主机上启动应用程序并在 Google Chrome 中打开它时,只有一些图像未加载。因为它们被缓存了。因此,如果我在 Microsoft Edge 等中打开应用程序,所有图标/图像都会出现同样的错误。
这取决于您使用的 Spring Boot 版本。对于 Spring Boot 3.1 或更高版本,VaadinWebSecurity 中的配置如下所示(下面的代码并不完整,但显示了相关部分)。
@Configuration
public class SecurityConfig extends VaadinWebSecurity {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(
authorize -> authorize.requestMatchers(new AntPathRequestMatcher("/images/*.png"),
new AntPathRequestMatcher("/icons/*.png"), new AntPathRequestMatcher("/icons/*.svg"))
.permitAll());
super.configure(http);
setLoginView(http, LoginView.class);
}
}