I tried to fetch localhost:8080 spring-boot application and I got the following error in the console.
Access to XMLHttpRequest at 'http://localhost:8080/' from origin 'http://localhost:3000' has been blocked by CORS policy:
I did the following changes in SpringSecurityConfig class file:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().exceptionHandling()
.authenticationEntryPoint(restAuthEntry).and()
.authorizeRequests((request) -> request.antMatchers("/api/v1/auth/login").permitAll()
.antMatchers(HttpMethod.OPTIONS, "/**").permitAll())
.addFilterBefore(new JWTAuthenticationFilter(userService, jWTTokenHelper),
UsernamePasswordAuthenticationFilter.class);
http.csrf().disable().cors().and().headers().frameOptions().disable();
}
This solved..