Spring-boot读书笔记一LoginController
The LoginController is invoked in several ways:
1. Direct URL Access
When users navigate to /login in their browser, Spring's DispatcherServlet routes the request to the LoginController.login() method.
2. Spring Security Redirect
- From your SecurityConfiguration.java: .formLogin().loginPage("/login")
- Spring Security automatically redirects unauthenticated users to /login when they try to access protected resources.
3. Automatic Spring Boot Registration
- The @Controller annotation makes Spring automatically discover and register this controller
- Spring Boot's auto-configuration scans for @Controller classes in the package hierarchy
- The @GetMapping("/login") maps HTTP GET requests to /login URL to the login() method
Flow:
- User tries to access a protected page (like /courses)
- Spring Security intercepts the request
- Since user is not authenticated, Security redirects to /login
- LoginController.login() method is invoked
- Returns "login" view name, which renders the login page template
The controller is essentially the bridge between the security configuration and the login page view.

浙公网安备 33010602011771号