当前位置: 首页 > 知识库问答 >
问题:

Spring Boot AuthenticationManagerBean不工作

卜飞鸣
2023-03-14

在我的项目中,当我试图通过重写AuthenticationManagerBean()方法为AuthenticationManager定义bean时,它显示了以下错误,

SecurityConfiguration类型的authenticationManagerBean()方法必须重写或实现超类型方法

下面给出了我定义的方法,

 @Bean(name = BeanIds.AUTHENTICATION_MANAGER)
 @Override
 public AuthenticationManager authenticationManagerBean() throws Exception {
    return super.authenticationManagerBean();
 }


我的整个安全配置类如下所示,

package com.toorjaridwan.introvertreadersauth.Configuration;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.BeanIds;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import com.toorjaridwan.introvertreadersauth.Service.UserDetailService;

@Configuration
@EnableWebSecurity
public class SecurityConfiguration {

    @Autowired
    private UserDetailService userDetailService;

    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(userDetailService);
    }

    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable().authorizeRequests().antMatchers("/authenticate").permitAll()
        .anyRequest().authenticated();
    }

       @Bean(name = BeanIds.AUTHENTICATION_MANAGER)
       @Override
       public AuthenticationManager authenticationManagerBean() throws Exception {
           return super.authenticationManagerBean();
       }

    @Bean
    public PasswordEncoder passwordEncoder() {
        return NoOpPasswordEncoder.getInstance();
    }

}


在之前使用Spring Boot 2.1.9版本的项目中,一切都很顺利,没有任何问题。现在我使用的是Spring Boot版本2.2.6。我不知道这是否是原因。

在寻找解决方案时,我遇到了这个和这个。我发现事情和我做的一样。

我正在运行64位Ubuntu 16.04 LTS和Java版本1.8

共有1个答案

蔚弘量
2023-03-14

尝试添加

extends WebSecurityConfigurerAdapter

到您的配置类

 类似资料:
  • 我想在菜单栏文本被选中时更改它的颜色。 这里可能出了什么问题? 我尝试使用伪类':active',但没有得到应用。其中as':Hover'正在工作。 我还尝试使用'Router LinkActive',它应该添加类'Active-Link',但这也不起作用。 我在下面给出了HTML、SCCS和TS代码:

  • 我编写了一组简单的类,向一位朋友演示如何为AOP(而不是xml配置)使用注释。我们无法使@ComponentScan工作,并且AnnotationConfigApplicationContext getBean的行为也不正常。我想明白两件事。请参阅下面的代码: PersonOperationSI.java PersonOperations.java PersonOperationsConfigCl

  • 我正在Eclipse Neon中使用Hibernate工具(JBoss tools 4.4.0.Final)。现在,我想将数据库表反向工程为POJO对象和Hibernate映射文件。 我遵循了一些关于如何设置Eclipse来生成POJO对象的教程。在我运行配置之前,一切看起来都很好。什么都没发生,也没有抛出错误。有人能帮我吗?数据库是一个微软SQL服务器2014。 我的逆向工程配置文件看起来像:

  • 我正在尝试使用codeigniter insert\u batch将多行插入到我的数据库表中。根据错误报告,似乎没有设置表列。只是阵列的数量: 我的看法是: 我的控制器: 和型号:

  • 我尝试使用StreamWriter.WriteLine(不是静态地)将几行代码一次写到。txt文件中。 每个播放器对象都是字符串cosnatants。如果我使用不同的文件名(也称为BasicTestInfo2.txt),它会在bin.debug中创建该文件,但它是空的。我知道我到达了using块的内部(我在里面放了一个console.writeline),我知道我想要截断,这就是为什么我对appe

  • 我正在尝试使用yii2邮件组件发送电子邮件。 配置web。php 还有我的代码。 我收到了这个错误。 Swift\u TransportException预期响应代码为250,但收到代码“535”,消息“535-5.7.8用户名和密码不被接受。有关详细信息,请访问535 5.7.8https://support.google.com/mail/?p=BadCredentialsa13-v6sm41

  • 问题内容: 似乎不起作用,但确实起作用。有什么想法吗? 问题答案: 您不能在Java中将基本类型用作通用参数。改为使用: 使用自动装箱/拆箱,代码几乎没有区别。自动装箱意味着您可以编写: 代替: 自动装箱意味着将第一个版本隐式转换为第二个版本。自动拆箱意味着您可以编写: 代替: 如果未找到键,则隐式调用意味着将生成一个,例如: 原因是类型擦除。例如,与C#不同,泛型类型不会在运行时保留。它们只是显