Java 无法解析类型org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter

Java 无法解析类型org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter,java,spring,spring-boot,spring-security,Java,Spring,Spring Boot,Spring Security,我一直在努力学习春季安全。下面的代码来自,我使用了相同的pom.xml文件和spring引导版本 package com.demo.hello; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.build

我一直在努力学习春季安全。下面的代码来自,我使用了相同的
pom.xml
文件和spring引导版本

package com.demo.hello;

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.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .antMatchers("/", "/home").permitAll()
                .anyRequest().authenticated()
                .and()
            .formLogin()
                .loginPage("/login")
                .permitAll()
                .and()
            .logout()
                .permitAll();
    }

    @Bean
    @Override
    public UserDetailsService userDetailsService() {
        UserDetails user =
             User.withDefaultPasswordEncoder()
                .username("user")
                .password("password")
                .roles("USER")
                .build();

        return new InMemoryUserDetailsManager(user);
    }
}
我仍然在
configure
方法中遇到以下错误

The type org.springframework.security.web.authentication.UsernamePassw
     ordAuthenticationFilter cannot be resolved. It is indirectly 
     referenced from required .class files

当我使用spring-boot-1.5.14时,没有显示错误,但它不适用于spring-boot-2.0.3,并且的代码使用2.0.3版本。
我无法找出哪里出了问题

我通过从列表中删除以下文件夹解决了问题

maven存储库并更新了项目

  • .m2\repository\org\springframework\security\spring security config\5.0.6.RELEASE
  • .m2\repository\org\springframework\security\spring security web\5.0.6发行版
  • .m2\repository\org\springframework\security\spring security core\5.0.6发行版
  • .m2\repository\org\springframework\boot\spring boot starter security\2.0.3.RELEASE

  • 遇到了同样的问题。 在我的例子中,问题是由于“SpringBootStarter安全性”依赖项不匹配。添加了新的“spring boot starter安全性”,兼容版本解决了此问题

    所谓兼容性,我指的是其他
    org.springframework.boot
    依赖项的版本

    希望这可以帮助别人