为什么 VAADIN 项目中不显示 /icons/** 文件夹中的图标?

问题描述 投票:0回答:1

我正在生产 Spring Boot Vaadin 项目。在此项目中,我在 /resources/META-INF/resources/icons(images) 中使用自定义图像和图标。我使用 nl.martijndwars 依赖项在我的项目中添加了推送通知。 在指南中,我需要将 sw.ts(Service Worker 文件,由 vaadin 生成)移动到前端文件夹。自从我完成后,我的一些自定义图标并不总是加载。 (405代码。不允许使用GET方法) mistake code

当我在本地主机上启动应用程序并在 Google Chrome 中打开它时,只有一些图像未加载。因为它们被缓存了。因此,如果我在 Microsoft Edge 等中打开应用程序,所有图标/图像都会出现同样的错误。

我尝试过的: 我认为问题出在 spring 安全配置中。所以我尝试了不同的方法来允许 spring 配置中的图标文件夹 spring security config
spring security config 2

也许主要问题是通过这个脚本(sw.ts)缓存图像? sw.ts 请帮忙!我想要回我的图标/图像!)

spring-boot push-notification icons vaadin service-worker
1个回答
0
投票

这取决于您使用的 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);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.