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

n3h0vuf2  于 5个月前  发布在  Spring
关注(0)|答案(1)|浏览(75)

我有春 Boot (2.5.4)Vaadin(21)项目在生产中。在这个项目中,我使用自定义图像和图标/resources/META-INF/resources/icons(images)。我在我的项目中添加了推送通知,使用nl.martijndwars依赖。在指南中,我需要移动我的sw.ts(Service Worker文件,由vaadin生成)到前端文件夹。因为我已经这样做了,我的一些自定义图标并不总是加载。(405代码。不允许GET方法)mistake code
当我在本地主机上启动应用程序并在谷歌Chrome中打开它时,只有一些图像没有加载。因为它们被缓存了。所以,如果我在例如微软Edge中打开应用程序,所有图标/图像都以同样的错误消失了。
我尝试过的:我认为问题出在spring安全配置中。所以我尝试了不同的方法来允许spring配置spring security config中的图标文件夹
spring security config 2
也许主要的问题是缓存图像由这个脚本(sw.ts)?sw.ts请,帮助!我想我的图标/图像回来!)

cyej8jka

cyej8jka1#

这取决于您使用的Sping Boot 版本。使用Sping 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);
    }
}

字符串

相关问题