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
相关产品推荐
相关产品推荐

