You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vaadin 24+Spring Boot3下如何让指定URL不被Vaadin处理?

解决Vaadin 24 + Spring Boot 3中排除URL路径不生效的问题

以下是针对你的问题的具体解决步骤:

  • 确认配置格式正确性
    检查application.properties中的vaadin.exclude-urls配置,确保逗号分隔时没有空格,正确格式应为:

    vaadin.exclude-urls=/api/**,/swagger-ui/**,/v3/api-docs/**
    

    (额外添加/v3/api-docs/**是为了确保OpenAPI文档路径也不被Vaadin拦截)

  • 改用Java代码配置URL排除规则
    若properties配置未生效,直接通过代码配置Vaadin Servlet的排除路径,确保配置被正确加载:

    @Configuration
    public class VaadinServletConfig {
    
        @Bean
        public VaadinServletRegistrationBean vaadinServletRegistrationBean() {
            VaadinServletRegistrationBean registration = new VaadinServletRegistrationBean(new VaadinServlet(), "/*");
            // 设置排除路径,逗号分隔无空格
            registration.addInitParameter(
                VaadinServlet.URL_EXCLUSION_PATTERNS_PARAMETER,
                "/api/**,/swagger-ui/**,/v3/api-docs/**"
            );
            return registration;
        }
    }
    
  • 确保SpringDoc端点被DispatcherServlet处理
    验证SpringDoc的依赖是否适配Spring Boot 3,应使用springdoc-openapi-starter-webmvc-ui(版本2.x及以上),确保/swagger-ui/**和/v3/api-docs/**由Spring的DispatcherServlet托管,而非Vaadin Servlet。

  • 排查Spring Security拦截干扰
    若项目使用Spring Security,需在安全配置中允许相关路径的访问,避免被拦截后转发至Vaadin页面:

    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        http.authorizeHttpRequests(auth -> auth
                .requestMatchers("/api/**", "/swagger-ui/**", "/v3/api-docs/**").permitAll()
                .anyRequest().authenticated()
        );
        // 若启用了CSRF,需排除Swagger相关路径
        http.csrf(csrf -> csrf.ignoringRequestMatchers("/api/**", "/swagger-ui/**", "/v3/api-docs/**"));
        return http.build();
    }
    
  • 清除浏览器缓存测试
    使用浏览器无痕模式访问/swagger-ui/index.html,避免之前缓存的Vaadin路由规则干扰请求处理。

  • 检查Vaadin路由配置
    确认项目中没有通过@Route注解将swagger-ui相关路径映射为Vaadin视图,避免路由冲突。

内容的提问来源于stack exchange,提问作者Evan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 20:38:11