我启动了一个Spring启动应用程序,到目前为止,除了设计之外我还有最少量的代码。实体和域类在下面提供,
Authority
班,
public class Authority implements GrantedAuthority {
private final String authority;
public Authority(String authority) {
this.authority = authority;
}
@Override
public String getAuthority() {
return null;
}
}
Role
班,
@Entity
public class Role {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int roleId;
}
UserRole
班,
@Entity
public class UserRole {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
}
User
班,
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
}
提供了安全配置类,
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private Environment environment;
private BCryptPasswordEncoder passwordEncoder() {
return null;
}
private static final String[] PUBLIC_MATCHERS = {
"/css/**",
"/js/**",
"/image/**",
"/fonts/**",
"/",
"/login",
"/forgetpassword",
"/newuser"
};
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.authorizeRequests().
/* antMatchers("/**").*/
antMatchers(PUBLIC_MATCHERS).
permitAll().anyRequest().authenticated();
httpSecurity
.csrf().disable().cors().disable()
.formLogin().failureUrl("/login?error")
/*.defaultSuccessUrl("/")*/
.loginPage("/login").permitAll()
.and()
.logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/?logout").deleteCookies("remember-me").permitAll()
.and()
.rememberMe();
}
/*
* global configuration for the user security
* */
}
提供了控制器类,
@Controller
@RequestMapping(value = "/")
public class HomeController {
@GetMapping
public String index() {
return "index";
}
@GetMapping(value = "login")
public String login() {
return "account";
}
@GetMapping(value = "forgetpassword")
public String forgetPassword() {
return "account";
}
@PostMapping(value = "newuser")
public String newUserPost() {
return "account";
}
@GetMapping(value = "newuser")
public String newUser() {
return "profile";
}
}
Spring启动了课程,
@SpringBootApplication
public class EcommerceApplication {
public static void main(String[] args) {
SpringApplication.run(EcommerceApplication.class, args);
}
}
我声明要收到错误,
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'inMemoryUserDetailsManager' defined in class path resource [org/springframework/boot/autoconfigure/security/AuthenticationManagerConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.provisioning.InMemoryUserDetailsManager]: Factory method 'inMemoryUserDetailsManager' threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.security.provisioning.InMemoryUserDetailsManager.<init>([Lorg/springframework/security/core/userdetails/UserDetails;)V
这里有什么问题?