I'm trying to allow cors from the same server, with port 3000.
As I don't know where my server is going to be deployed, I tried to access the server name as string than concat it with my desired port.
So here is my approach :
@SpringBootApplication
public class TestApplication {
@Autowired
private HttpServletRequest request;
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
@Bean
public WebMvcConfigurer corsConfigurer() {
System.out.println(request.getServerName());
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry
.addMapping("/**")
.allowedOrigins(request.getServerName()+":3000");
}
};
}
}
I think these are the highlights of my error message :
Error creating bean with name 'corsConfigurer'
org.springframework.beans.BeanInstantiationException: Failed to instantiate
java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread?