application.properties에 sql문 보여주기 추가/ CORS
<application>
//테이블 (형식이 다를때..?) 싹 다 지우고 다시 만든다
spring.jpa.hibernate.ddl-auto=create-drop
//sql문 예쁘게 보여주기
spring.jpa.properties.hibernate.format_sql= true
spring.jpa.properties.hibernate.show_sql= true
<build.gradle>
//aws mysql
//implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'mysql:mysql-connector-java'
CORS 해결
<config>
@Bean
public CorsConfigurationSource configurationSource(){
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOriginPatterns(Arrays.asList("*"));
configuration.setAllowedMethods(Arrays.asList("POST","GET","DELETE","PUT", "PATCH"));
configuration.setAllowedHeaders(Arrays.asList("*"));
configuration.setAllowCredentials(true);
configuration.addExposedHeader("*");
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
위에서
configuration.setAllowedHeaders(Arrays.asList("*"));
configuration.setAllowCredentials(true);
configuration.addExposedHeader("*");
이게 핵심인지도..?
이건가...???
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://localhost:3000")
.allowedMethods(HttpMethod.POST.name(), HttpMethod.GET.name(),
HttpMethod.PUT.name(), HttpMethod.DELETE.name())
.exposedHeaders("*");
}
}