failing to Autowire the AuthenticationContext class

@Component
public class SecurityService {

private final AuthenticationContext authenticationContext;


public SecurityService(AuthenticationContext authenticationContext) {
    this.authenticationContext = authenticationContext;
}

public UserDetails getAuthenticatedUser() {
    return authenticationContext.getAuthenticatedUser(UserDetails.class).get();
}

public void logout() {
    authenticationContext.logout();
}

}

Am getting the error Parameter 0 of constructor in com.example.application.security.SecurityService required a bean of type ‘com.vaadin.flow.spring.security.AuthenticationContext’ that could not be found.

The bean is created by the Vaadin security configuration, what’s your security configuration?

java 
public class SecurityConfig extends VaadinWebSecurity {
    
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeHttpRequests()
        .requestMatchers("/images/*.png").permitAll();
        super.configure(http);
        setLoginView(http, LoginView.class);
    }
    
    @Bean
    public UserDetailsService users() {
        UserDetails user = User.builder()
                .username("user")
                .password("{bcrypt}$2a$10$GRLdNijSQMUvl/au9ofL.eDwmoohzzS7.rmNSJZ.0FxO/BTk76klW")
                .roles("USER")
                .build();
        
        UserDetails admin = User.builder()
                .username("admin")
                .password("{bcrypt}$2a$10$GRLdNijSQMUvl/au9ofL.eDwmoohzzS7.rmNSJZ.0FxO/BTk76klW")
                .roles("USER","ADMIN")
                .build();
        
        return new InMemoryUserDetailsManager(user, admin);
        
    }

}

With the annotations ?
@EnableWebSecurity @Configuration

(Is it a new project or did you change something in your project?)

Yes The class has those , i ommited them in the code

Am following the tutorial on https://vaadin.com/docs/latest/tutorial/login-and-authentication

I think the SecurityConfig is ignored. Maybe the SecurityConfig is not in the same package or in a subpackage of the Application.java.

Sorry I think am half awake, I didn’t include the annotations @EnableWebSecurity
@Configuration on the SecurityConfig class. Error gone after putting them . Thanks a lot