Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用自己的登录页进行Spring安全登录不起作用_Spring_Spring Mvc_Spring Security - Fatal编程技术网

使用自己的登录页进行Spring安全登录不起作用

使用自己的登录页进行Spring安全登录不起作用,spring,spring-mvc,spring-security,Spring,Spring Mvc,Spring Security,我尝试使用自己的登录页面登录,出现以下错误: 白标错误页 此应用程序没有/error的显式映射,因此您将其视为回退。 2017年8月22日星期二07:52:15 CEST 出现意外错误(类型=未找到,状态=404)。 没有可用的消息 这是我的安全配置 @Configuration @EnableGlobalMethodSecurity(prePostEnabled = true) @EnableWebSecurity public class SecurityConfiguration exte

我尝试使用自己的登录页面登录,出现以下错误:

白标错误页 此应用程序没有/error的显式映射,因此您将其视为回退。 2017年8月22日星期二07:52:15 CEST 出现意外错误(类型=未找到,状态=404)。 没有可用的消息

这是我的安全配置

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
         http.authorizeRequests().antMatchers("/login", "/css/**",
         "/image/**").permitAll().anyRequest()
         .authenticated().and().formLogin().loginPage("/login.html").permitAll()
        .and().logout().permitAll().and().csrf().disable();
    }

    @Autowired
    protected void configureLDAP(AuthenticationManagerBuilder auth) throws Exception {
        auth.ldapAuthentication().userSearchFilter("uid={0}").contextSource()
                .url("ldap://ldap.forumsys.com:389/dc=example,dc=com").managerPassword("password");
}
登录


登录

使用Spring的登录页面,它可以正常工作

我认为您对
loginPage
方法的作用感到困惑。JavaDoc:

指定在需要登录时向用户发送的URL

您必须提供客户端将重定向到的URL

loginPage(“/login.html”)
更改为
loginPage(“/login”)
并为该url配置视图解析。例如,您可以创建另一个配置,如下所示:

@Configuration    
public class LoginViewConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/login").setViewName("login");
    }
}

或者将类似的东西添加到现有的mvc配置中。这假设您在其他地方配置了视图重新加载。

spring找不到错误页。可能您必须在
configure()
中添加该错误页。你应该用谷歌搜索你的错误信息。答案就在那里。像这样或者我认为问题是,spring找不到我的登录页面。它不工作。我现在得到了以下错误:白标签错误页面此应用程序没有/error的显式映射,所以您将其视为一种回退。2017年8月22日星期二15:53:23 CEST出现意外错误(类型=内部服务器错误,状态=500)。循环视图路径[login]:将再次分派回当前处理程序URL[/login]。检查您的ViewResolver设置!(提示:这可能是由于生成默认视图名称而导致的未指定视图。)看起来您根本没有配置视图解析。
@Configuration    
public class LoginViewConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/login").setViewName("login");
    }
}