카테고리 없음

CROS React, Spring

hoonssss 2023. 10. 12. 00:33
반응형
SMALL
package com.in28minutes.rest.webservices.restfulwebservices;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication
public class RestfulWebServicesApplication {

	public static void main(String[] args) {
		SpringApplication.run(RestfulWebServicesApplication.class, args);
	}

	@Bean
	public WebMvcConfigurer corsConfigurer() { //cros
		return new WebMvcConfigurer() { //WebMvcConfigurer클래스 생성
			public void addCorsMappings(CorsRegistry registry) { //addCorsMappings 오버라이드
				registry.addMapping("/**").allowedMethods("*").allowedOrigins("http://localhost:3000/");
			}
		};
	}
}
반응형
LIST