- spring security, spring data jpa, spring web, lombok, mysql Dependecy추가
- 스프링 3.1.1,java 17
- corsconfig파일
@Configuration
@RequiredArgsConstructor
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
ArrayList<String> allowedOriginPatterns = new ArrayList<>();
allowedOriginPatterns.add("http://localhost:3000");
allowedOriginPatterns.add("http://localhost:8080");
String[] patterns = allowedOriginPatterns.toArray(String[]::new);
registry.addMapping("/**")
.allowedMethods("*")
.allowedOriginPatterns(patterns)
.allowCredentials(true)
.maxAge(3600L);
}
}
- spring security기본설정
@Configuration
@RequiredArgsConstructor
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
ArrayList<String> allowedOriginPatterns = new ArrayList<>();
allowedOriginPatterns.add("http://localhost:3000");
allowedOriginPatterns.add("http://localhost:8080");
String[] patterns = allowedOriginPatterns.toArray(String[]::new);
registry.addMapping("/**")
.allowedMethods("*")
.allowedOriginPatterns(patterns)
.allowCredentials(true)
.maxAge(3600L);
}
}
유익한 글이었습니다.