小编Fub*_*000的帖子

Spring + H2DB-Web-Console:“此方法无法确定这些模式是否是 Spring MVC 模式。”

我的最终目标是在我的应用程序中使用h2db-web-console,作为我本地开发环境的一部分。

我收到错误:

原因:java.lang.IllegalArgumentException:此方法无法确定这些模式是否是 Spring MVC 模式。如果此端点是 Spring MVC 端点,请使用 requestMatchers(MvcRequestMatcher); 否则,请使用 requestMatchers(AntPathRequestMatcher)。

这是因为您的 servlet 上下文中有多个可映射 servlet:{org.h2.server.web.JakartaWebServlet=[/my-h2-console/*], org.springframework.web.servlet.DispatcherServlet=[/] }。

对于每个 MvcRequestMatcher,调用 MvcRequestMatcher#setServletPath 来指示 servlet 路径。

虽然这听起来很有描述性,但它让我发疯,因为看起来我为 JakartaWebServlet=[ /my-h2-console/ *]使用哪条路径并不重要,因为 DispatcherServlet=[ / ] 简单地匹配所有内容。以“/”开头......这就是一切。

...请使用 requestMatchers(MvcRequestMatcher); 否则,请使用 requestMatchers(AntPathRequestMatcher)...

好吧,这些在 Spring 3.xx补丁说明中已被弃用,因此我尝试使用 RequestMatcher(这应该自动与“授权”一起使用)。

安全配置

    @Bean
    @Order(GENERAL_SECURITY_CONFIGURATION_ORDER)
    fun securityFilterChain(http: HttpSecurity): SecurityFilterChain {
        http {
            ...
            }
            securityMatcher("/**")
            headers { frameOptions { disable() } }
            csrf { ignoringRequestMatchers("/my-h2-console/**") }

            authorizeRequests {
                authorize("/my-h2-console/**", permitAll)
                authorize("/ping", permitAll)
                authorize("/**", denyAll)
            }
        }
        return http.build() …
Run Code Online (Sandbox Code Playgroud)

spring-mvc h2 spring-security spring-boot web-console

3
推荐指数
1
解决办法
6259
查看次数