spring boot 정적 자원 크로스 도 메 인 설정

984 단어 Springboot
spring boot 의 크로스 도 메 인 설정 은 addCorsMappings 를 통 해 이 루어 집 니 다. 정적 자원 에 대해 서 는 이 설정 이 적용 되 지 않 은 것 같 습 니 다.
여러 번 의 실험 을 통 해 addResource Handlers 를 증가 시 키 면 이 문 제 를 해결 할 수 있 습 니 다. 기록 해 보 세 요.
본인 에 게 이것 은 현지 테스트 의 임시 방법 일 뿐 생산 환경 은 이 방법 을 추천 하지 않 습 니 다.
@Configuration
@EnableWebMvc
public class WebConfiguration extends WebMvcConfigurerAdapter {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
            .allowedOrigins("*","null")
            .allowedMethods("POST", "GET","PUT", "DELETE");

    }
    

    
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
                      
        registry.addResourceHandler("/common/**")
        .addResourceLocations("file:/Users/lilidan/Documents/workspace/shana-laboratory-web/src/main/webapp/common/")
        .setCachePeriod(1);
    }
    
}

좋은 웹페이지 즐겨찾기