addCorsMappings metodu
Örnek
Şöyle yaparız
Açıklaması şöyleimport org.springframework.context.annotation.Configuration;import org.springframework.web.servlet.config.annotation.CorsRegistry;import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;@Configurationpublic class WebMvcConfig implements WebMvcConfigurer {@Overridepublic void addCorsMappings(CorsRegistry registry) {registry.addMapping(“/**”).allowedMethods(“*”).allowedHeaders(“*”).allowedOrigins(“http://192.168.1.9:3000”).allowCredentials(false).maxAge(-1);}}
- “*” means it will accept any allowable value for that field. For example, allowedMethods will accept GET, POST, PUT, DELETE, OPTIONS, etc. @see org.springframework.http.HttpMethod.- allowedOrigins, tells Spring to only accept Ajax requests from these URL patterns.- maxAge — indicates how long to cache the result of a CORS preflight request.
Hiç yorum yok:
Yorum Gönder