Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- springboot
- :src
- 소돌엔
- @ Deprecated
- 명령어
- @Overloading
- 네스트제이에스
- 카페
- Vue
- DTO typr
- TypeScript
- 페이지 라우팅
- 돌소
- vue install
- React
- 웹용어
- 순환종송석
- forwardRef()
- java
- 돌소엔
- npx install create-react-app
- nestJS
- WEB
- 권한세팅
- Port ~ was already in use.
- BFF Pattern
- linux
- request dto
- Web server failed to start.
- 필수명령어
Archives
- Today
- Total
유바바아들 닮은 개발자의 끄적끄적
[ Spring Boot ] CORS 세팅 코드 를 알아보자 본문
웹 개발을 하다 보면 한 번씩 꼭 만나는 수문장 같은 CORS를 해결할 수 있는 코드에 대해서 알아보자.
1. CorsConfig 클래스 하나를 만들어준다. 아래 코드를 복붙한다.
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOriginPatterns("*")
.allowedMethods("GET", "POST", "PUT", "DELETE")
.allowedHeaders("*")
.allowCredentials(true)
.maxAge(3600);
}
}
그럼 끝이다! 더추가할 옵션 및 설정해야 할 옵션이 있다면 수정해 주자.
728x90
LIST
'Stpring Boot' 카테고리의 다른 글
[ Spring Boot ] @Override @Overloading 안헷갈리는 방법 (2) | 2023.07.21 |
---|---|
[ Spring Boot ] Web server failed to start. Port 8080 was already in use. 이슈 해결하기. (2) | 2023.06.13 |