PackageCom.github.carter659.spring13;Importjavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse;Importjavax.servlet.http.HttpSession;ImportOrg.springframework.context.annotation.Bean;Importorg.springframework.context.annotation.Configuration;Importorg.springframework.web.servlet.config.annotation.InterceptorRegistration;ImportOrg.springframework.web.servlet.config.annotation.InterceptorRegistry;ImportOrg.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;ImportOrg.springframework.web.servlet.handler.HandlerInterceptorAdapter;/*** Login Configuration Blog Source:http://www.cnblogs.com/GoodHelper/ * */@Configuration Public classWebsecurityconfigextendsWebmvcconfigureradapter {/*** Login Session key*/ Public Final StaticString Session_key = "User"; @Bean Publicsecurityinterceptor Getsecurityinterceptor () {return NewSecurityinterceptor (); } Public voidaddinterceptors (Interceptorregistry registry) {Interceptorregistration Addinterceptor=Registry.addinterceptor (Getsecurityinterceptor ()); //Exclude ConfigurationAddinterceptor.excludepathpatterns ("/error"); Addinterceptor.excludepathpatterns ("/login**"); //interception ConfigurationAddinterceptor.addpathpatterns ("/**"); } Private classSecurityinterceptorextendsHandlerinterceptoradapter {@Override Public BooleanPrehandle (httpservletrequest request, httpservletresponse response, Object handler)throwsException {HttpSession session=request.getsession (); if(Session.getattribute (session_key)! =NULL) return true; //Jump LoginString url = "/login"; Response.sendredirect (URL); return false; } }}
Exclude configuration there, do not send the past to verify the login URL, also to intercept, this reason, tossing me half an hour
Exclude Configuration
Addinterceptor.excludepathpatterns ("/login**");
Https://www.cnblogs.com/GoodHelper/p/6343190.html
A small reason to use Webmvcconfigureradapter for login, failure