Spring Boot with Spring Security app calls login controller when loading home page
<p>I have a Spring Boot application with Spring Security. At the basic level it pretty much matches the one from Spring's tutorial. My question is, when I hit the home page, it calls the login controller (twice). Why? It's not readily apparent that it does so with the basic setup, since it just shows the home page. But if I add a LoginController class, it gets called (twice) when loading the home page. Another way to see this is to add an invalid thymeleaf tag to login.html templage, it'll throw an error, even though the home page is not supposed to be authenticated. Any explanation would be of help.</p>

<p>My code:</p>

<p>Application:</p>

<pre><code>@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
</code></pre>

<p>WebSecurityConfig:</p>

<pre><code>@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .antMatchers("/").permitAll()
                .anyRequest().authenticated()
                .and()
            .formLogin()
                .loginPage("/login")
                .permitAll()
                .and()
            .logout()
                .permitAll();
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .inMemoryAuthentication()
                .withUser("user").password("password").roles("USER");
    }
}
</code></pre>

<p>HomeController:</p>

<pre><code>@Controller
public class HomeController {
    @RequestMapping(value="/", method=RequestMethod.GET)
    public String getHomePage(Model model) {
        return "home";
    }
}
</code></pre>

<p>Optional LoginController, will get called when hitting the home page:</p>

<pre><code>@Controller
public class LoginController {
    @RequestMapping(value="/login", method=RequestMethod.GET)
    public String getLoginPage(Model model) {
        return "login";
    }
}
</code></pre>