I’m working on a little Spring Boot project with spring security
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
I want the home page to be accessible without any login, so I did the following class in the com.example.myproject package:
@Configuration
@EnableWebSecurity
public class SecurityConfiguration {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http.authorizeHttpRequests((request) -> request
.requestMatchers("/", "/home").permitAll()
).build();
}
Unfortunately when I go to http://localhost:8080/home or http://localhost:8080/ I always get the login prompt and I can see I’ve been redirected to http://localhost:8080/login.
Why is my configuration not working?