NoSuchBeanDefinitionException: Keine qualifizierende Bean vom Typ „org.springframework.security.config.annotation.web.buJava

Java-Forum
Anonymous
 NoSuchBeanDefinitionException: Keine qualifizierende Bean vom Typ „org.springframework.security.config.annotation.web.bu

Post by Anonymous »

Ich versuche, die Basisauthentifizierung mit Spring Boot einzurichten und erhalte beim Start immer wieder diese Fehlermeldung. Ich habe mehrere Beispiele mit fast genau demselben Code wie hier gesehen und kann nicht sagen, was ich falsch mache. Ich habe meinen Code mit nur geringfügigen Änderungen aus der Spring-Dokumentation kopiert. Ich bin noch ganz neu im Frühling und das kommt mir alles wie Hexerei vor, daher wäre ich für eure Erkenntnisse sehr dankbar.
Code:

Code: Select all

package com.project.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.security.web.SecurityFilterChain;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

@Configuration
public class BasicAuthSecurityConfiguration
{
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests().anyRequest().authenticated()
.and()
.httpBasic();

return http.build();
}

@Bean
public InMemoryUserDetailsManager userDetailsService() throws IOException {
String rootPath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
String appConfigPath = rootPath + "application.properties";
Properties appProps = new Properties();
appProps.load(new FileInputStream(appConfigPath));

UserDetails user = User
.withUsername(appProps.getProperty("requestUsername"))
.password(appProps.getProperty("requestPassword"))
.roles("USER")
.build();
return new InMemoryUserDetailsManager(user);
}
}
Fehlermeldung:

Code: Select all

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method filterChain in com.atscale.service.BasicAuthSecurityConfiguration required a bean of type 'org.springframework.security.config.annotation.web.builders.HttpSecurity' that could not be found.

Action:

Consider defining a bean of type 'org.springframework.security.config.annotation.web.builders.HttpSecurity' in your configuration.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post