找不到Spring默认登录页面

时间:2015-09-19 17:15:51

标签: java spring security login default

这是我的安全配置:

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter{

    @Autowired
    private UserDetailsServiceImpl userDetailsService;

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth
                .userDetailsService(userDetailsService)
                .passwordEncoder(bCryptPasswordEncoder());
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .formLogin()
                .and()
                .authorizeRequests()
                .antMatchers("/admin").hasAnyAuthority("ROLE_ADMIN")
                .anyRequest().permitAll();
    }

    @Bean
    public BCryptPasswordEncoder bCryptPasswordEncoder(){ return new BCryptPasswordEncoder(); }

我希望在/ login看到默认登录页面,但是我收到404错误。我的配置可能有什么问题?

1 个答案:

答案 0 :(得分:0)

这是解决方案 http://docs.spring.io/spring-security/site/docs/current/guides/html5/hellomvc-javaconfig.html#registering-spring-security-with-the-war

我没有声明必需的MessageSecurityWebApplicationInitializer课程。