Пытался изучить весеннюю безопасность. Следующий код взят из Spring.io, и я использовал тот же файл pom.xml и версию весенней загрузки.
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, а код Spring.io использует версию 2.0.3.
Я не могу понять, что не так




Я решил проблему, удалив следующие папки из
репозиторий maven и обновил проект
Наткнулся на ту же проблему. В моем случае проблема возникла из-за несоответствия зависимости «весна-загрузка-стартер-безопасность». добавлен новый "spring-boot-starter-security" с совместимой версией, решена эта проблема
Под совместимостью я имел в виду версии других зависимостей <groupId>org.springframework.boot</groupId>.
Надеюсь, это может кому-то помочь !!