为什么我在将Spring Security版本从5升级到6后会出现异常?

m1m5dgzv  于 2023-10-20  发布在  Spring
关注(0)|答案(1)|浏览(331)

将Spring Security从5迁移到6.0。在异常之后,我尝试了所有可能的解决方案,但都没有成功。谁来帮帮我。

java.lang.NullPointerException: Cannot invoke "org.springframework.security.authentication.AuthenticationManager.authenticate(org.springframework.security.core.Authentication)" because the return value of "org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.getAuthenticationManager()" is null
    at com.jmi.jabord.core.oauth.filter.AccessTokenAuthenticationFilter.attemptAuthentication(AccessTokenAuthenticationFilter.java:79)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:231)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:221)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:107)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:93)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374)

我试着在我的Filter类extends AbstractAuthenticationProcessingFilter中添加这个:

@Autowired
@Qualifier("authenticationManager")
@Override
public void setAuthenticationManager(AuthenticationManager authenticationManager) {
    super.setAuthenticationManager(authenticationManager);
}

但对我来说都没有用。

nr9pn0ug

nr9pn0ug1#

在安全配置类中,您可以尝试添加以下内容:

@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception {
    return authenticationConfiguration.getAuthenticationManager();
}

相关问题