微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将上下文路径更改为索引页面,但显示状态404

如何解决将上下文路径更改为索引页面,但显示状态404

我与此post一个类似的问题,我通过添加上下文路径获得状态404而不是索引页。我怀疑我做错了什么,例如将@EnableWebSecurity放在WebSecurityConfig文件或Controller中。

这是spring-boot配置

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests().antMatchers(
            "/registration**","/js/**","/css/**","/img/**").permitAll()
            .anyRequest().authenticated()
            .and()
            .formLogin()
            .loginPage("/login")
            .failureUrl("/bad-404")
            .defaultSuccessUrl("/")
            .usernameParameter("email") //needed,if custom login page
            .passwordParameter("password") //needed,if custom login page                
            .permitAll()
            .and()
            .logout()
            .invalidateHttpSession(true)
            .clearauthentication(true)
            .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
            .logoutSuccessUrl("/login?logout")
            .permitAll();

}

这是运行该应用程序的主要类

public static void main(String[] args) {
    System.setProperty("server.servlet.context-path","/index");
    SpringApplication.run(SmartcardApplication.class,args);
}

这是Controller类

@Controller
public class MainController {

    @GetMapping("/login")
    public String login() {
        return "login";
    }

    @GetMapping("/")
    public String home(){
        return "index";
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。