问题描述
我与此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 (将#修改为@)