最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Spring BootVaadin SecurityConfig BeanCreationException: filterChain() Not Found Despite Correct Setup (I'm pretty

programmeradmin2浏览0评论

I'm encountering a persistent BeanCreationException in my Spring Boot 3.2.2/Vaadin 24.6.6 application, and I've exhausted my troubleshooting options. The error message is: .springframework.beans.factory.BeanCreationException: Error creating bean with name 1 'VaadinSecurityFilterChainBean' defined in class path resource .../config/SecurityConfig.class]: No matching factory method found on class [... .config.SecurityConfig]: factory bean 'securityConfig'; factory method 'filterChain()'. Check that a method with the specified name exists and that it is non-static.

This error indicates that Spring is unable to find the filterChain() method in my SecurityConfig class.

Here's a breakdown of what I've tried:

  • Verified SecurityConfig.java:
    • The SecurityConfig.java file is in the correct package (com.clarkemiddle.skitripvaadin.config).
    • It has the @EnableWebSecurity and @Configuration annotations.
    • It extends VaadinWebSecurity.
    • The filterChain() method has the correct signature: @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception.
    • The method is not static.
  • Compilation and Class Files:
    • I've performed mvn clean install multiple times.
    • I've checked the target/classes/com/clarkemiddle/skitripvaadin/config directory, and SecurityConfig.class is present.
    • I have used a decompiler to check the contents of the SecurityConfig.class file, and the filter chain method is present.
  • Command-Line Execution:
    • I've run the application from the command line using mvn spring-boot:run.
  • Dependency Checks:
    • I've used mvn dependency:tree to check for conflicting dependencies.
    • I have tried explicitly defining the vaadin-spring-security version in my pom.xml.
  • Minimal Configuration:
    • I've tried a minimal SecurityConfig with just http.authorizeHttpRequests(auth -> auth.anyRequest().permitAll());.
  • New Project:
    • I've created a new Spring Boot/Vaadin project and copied my SecurityConfig.java and LoginView.java files, but the error persists.
  • IDE Checks:
    • I have invalidated my IDE's caches, and restarted the IDE.
  • Java Version:
    • I am using Java 17.
  • I have checked that the application class is in the correct package, and has the @SpringBootApplication annotation.

Here is my SecurityConfig.java:

import com.clarkemiddle.skitripvaadin.view.LoginView;
import .springframework.context.annotation.Bean;
import .springframework.context.annotation.Configuration;
import .springframework.security.config.annotation.web.builders.HttpSecurity;
import .springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import .springframework.security.core.userdetails.User;
import .springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import .springframework.security.crypto.password.PasswordEncoder;
import .springframework.security.provisioning.InMemoryUserDetailsManager;
import .springframework.security.provisioning.UserDetailsManager;
import com.vaadin.flow.spring.security.VaadinWebSecurity;
import .springframework.security.web.SecurityFilterChain;

@EnableWebSecurity
@Configuration
public class SecurityConfig extends VaadinWebSecurity {

@Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http.authorizeHttpRequests(auth -> auth
                .requestMatchers("/", "/register", "/login").permitAll()
                .anyRequest().authenticated()
        );

        setLoginView(http, LoginView.class);
        return http.build();
    }

    @Bean
    UserDetailsManager userDetailsManager() {
        // In a production application, replace InMemoryUserDetailsManager with a database-backed UserDetailsService
        return new InMemoryUserDetailsManager(
                User.withUsername("username")
                        .password(passwordEncoder().encode("123456"))
                        .roles("USER").build()
        );
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

And my dependencies:

 <dependencies>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.33</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-bom</artifactId>
                <version>${vaadin.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

I'm encountering a persistent BeanCreationException in my Spring Boot 3.2.2/Vaadin 24.6.6 application, and I've exhausted my troubleshooting options. The error message is: .springframework.beans.factory.BeanCreationException: Error creating bean with name 1 'VaadinSecurityFilterChainBean' defined in class path resource .../config/SecurityConfig.class]: No matching factory method found on class [... .config.SecurityConfig]: factory bean 'securityConfig'; factory method 'filterChain()'. Check that a method with the specified name exists and that it is non-static.

This error indicates that Spring is unable to find the filterChain() method in my SecurityConfig class.

Here's a breakdown of what I've tried:

  • Verified SecurityConfig.java:
    • The SecurityConfig.java file is in the correct package (com.clarkemiddle.skitripvaadin.config).
    • It has the @EnableWebSecurity and @Configuration annotations.
    • It extends VaadinWebSecurity.
    • The filterChain() method has the correct signature: @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception.
    • The method is not static.
  • Compilation and Class Files:
    • I've performed mvn clean install multiple times.
    • I've checked the target/classes/com/clarkemiddle/skitripvaadin/config directory, and SecurityConfig.class is present.
    • I have used a decompiler to check the contents of the SecurityConfig.class file, and the filter chain method is present.
  • Command-Line Execution:
    • I've run the application from the command line using mvn spring-boot:run.
  • Dependency Checks:
    • I've used mvn dependency:tree to check for conflicting dependencies.
    • I have tried explicitly defining the vaadin-spring-security version in my pom.xml.
  • Minimal Configuration:
    • I've tried a minimal SecurityConfig with just http.authorizeHttpRequests(auth -> auth.anyRequest().permitAll());.
  • New Project:
    • I've created a new Spring Boot/Vaadin project and copied my SecurityConfig.java and LoginView.java files, but the error persists.
  • IDE Checks:
    • I have invalidated my IDE's caches, and restarted the IDE.
  • Java Version:
    • I am using Java 17.
  • I have checked that the application class is in the correct package, and has the @SpringBootApplication annotation.

Here is my SecurityConfig.java:

import com.clarkemiddle.skitripvaadin.view.LoginView;
import .springframework.context.annotation.Bean;
import .springframework.context.annotation.Configuration;
import .springframework.security.config.annotation.web.builders.HttpSecurity;
import .springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import .springframework.security.core.userdetails.User;
import .springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import .springframework.security.crypto.password.PasswordEncoder;
import .springframework.security.provisioning.InMemoryUserDetailsManager;
import .springframework.security.provisioning.UserDetailsManager;
import com.vaadin.flow.spring.security.VaadinWebSecurity;
import .springframework.security.web.SecurityFilterChain;

@EnableWebSecurity
@Configuration
public class SecurityConfig extends VaadinWebSecurity {

@Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http.authorizeHttpRequests(auth -> auth
                .requestMatchers("/", "/register", "/login").permitAll()
                .anyRequest().authenticated()
        );

        setLoginView(http, LoginView.class);
        return http.build();
    }

    @Bean
    UserDetailsManager userDetailsManager() {
        // In a production application, replace InMemoryUserDetailsManager with a database-backed UserDetailsService
        return new InMemoryUserDetailsManager(
                User.withUsername("username")
                        .password(passwordEncoder().encode("123456"))
                        .roles("USER").build()
        );
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

And my dependencies:

 <dependencies>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.33</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-bom</artifactId>
                <version>${vaadin.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
Share Improve this question asked Mar 8 at 6:15 Aerialdad14Aerialdad14 11 silver badge 3
  • What is the value of vaadin.version? – dan1st Commented Mar 8 at 6:40
  • <properties> <vaadin.version>24.6.6</vaadin.version> </properties> – Aerialdad14 Commented Mar 8 at 16:18
  • This error indicates that Spring is unable to find the filterChain() - that is not what the error indicates. Error creating bean with name 1 'VaadinSecurityFilterChainBean' line says that it can't find the bean called VaadinSecurityFilterChainBean. I am guessing that bean is sth you are trying to autowire somewhere (perhaps even as method parameter in filterChain() method or somewhere in that class? – asgarov1 Commented Mar 8 at 17:00
Add a comment  | 

1 Answer 1

Reset to default 2

Vaadin 24.6.6 does not work with Spring Boot 3.2, you need to use at least Spring Boot 3.4.

https://github/vaadin/platform/releases/tag/24.6.0

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论