spring boot2.0フィルタの設定


import org.springframework.boot.web.servlet.FilterRegistrationBean;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;
import javax.servlet.Filter;
@Configurationpublic class WebComponentConfig {
@Bean
public FilterRegistrationBean corsFilterRegistration() {
    FilterRegistrationBean registration = new FilterRegistrationBean();
    registration.setFilter(CorsFilter());
    registration.addUrlPatterns("/*");
    registration.setName("corsFilter");
    registration.setOrder(1);
    return registration;
}

@Bean
public FilterRegistrationBean apiFilterRegistration() {
    FilterRegistrationBean registration = new FilterRegistrationBean();
    registration.setFilter(ApiFilter());
    registration.addUrlPatterns("/ides/api/*");
    registration.setName("apiFilter");
    registration.setOrder(2);
    return registration;
}

@Bean
public Filter CorsFilter() {
    return new CorsFilter();
}

@Bean
public Filter ApiFilter() {
    return new ApiFilter();
}

}
CorsFilterクラスは、ドメイン間フィルタパス/*ApiFilterクラスインタフェース認証フィルタパスをサポートし、複数のフィルタの実行順序をregistrationによりカスタマイズする.setOrder(1);registration.setOrder(2); 文の設定