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

Vaadin 22升级至23启动报错:缺少VaadinDefaultRequestCache Bean

Vaadin 22升级到23后缺少VaadinDefaultRequestCache Bean的解决办法

问题原因

升级后启动报错找不到com.vaadin.flow.spring.security.VaadinDefaultRequestCache Bean,通常由以下原因导致:

  • Vaadin Spring Security相关依赖缺失
  • 配置类执行顺序或自动配置触发异常
  • Spring Boot版本与Vaadin 23不兼容

解决方案

1. 确认依赖配置

确保项目已引入对应Vaadin 23版本的Spring Security依赖:
Maven配置:

<dependency>
    <groupId>com.vaadin</groupId>
    <artifactId>vaadin-spring-security</artifactId>
    <version>23.3.24</version> <!-- 替换为你的Vaadin 23具体版本 -->
</dependency>

Gradle配置:

implementation 'com.vaadin:vaadin-spring-security:23.3.24'

2. 调整Security配置类

在现有配置基础上,手动注册VaadinDefaultRequestCache Bean并指定请求缓存:

@EnableWebSecurity
@Configuration
public class SecurityConfig extends VaadinWebSecurityConfigurerAdapter {
    @Autowired
    private AppCustomAuthenticationProvider authProvider;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.rememberMe().alwaysRemember(false);

        // 定义公开资源
        http.authorizeRequests().antMatchers("/VAADIN/**").permitAll();
        http.authorizeRequests().antMatchers("/services/**").permitAll();
        http.authorizeRequests().antMatchers("/newstool/unregister/**").permitAll();

        // 手动指定Vaadin请求缓存
        http.requestCache().requestCache(vaadinDefaultRequestCache());

        super.configure(http);
        setLoginView(http, LoginView.class);
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.authenticationProvider(authProvider);
    }

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/images/**");
        super.configure(web);
    }

    // 手动注册VaadinDefaultRequestCache Bean
    @Bean
    public VaadinDefaultRequestCache vaadinDefaultRequestCache() {
        return new VaadinDefaultRequestCache();
    }
}

3. 检查Spring Boot版本兼容性

Vaadin 23要求Spring Boot版本在2.6.x ~ 2.7.x区间内,确保项目使用的Spring Boot版本符合要求,避免版本不兼容导致自动配置失效。

4. 确认自动配置未被禁用

检查项目配置文件(如application.properties/application.yml),确保没有禁用Vaadin相关自动配置:

# 确保不存在类似禁用配置
# spring.autoconfigure.exclude=com.vaadin.flow.spring.VaadinWebSecurityConfiguration

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 08:25:17