[monitor] 后台跨域支持,升级springboot-2.4.13

This commit is contained in:
tomsun28
2021-11-30 00:46:57 +08:00
parent d189b4e547
commit 4d63afc669
2 changed files with 35 additions and 1 deletions

View File

@@ -0,0 +1,34 @@
package com.usthe.manager.config;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import java.util.Collections;
/**
* @author tom
* @date 2021/11/29 21:31
*/
@Configuration
public class SecurityCorsConfiguration {
@Bean
public FilterRegistrationBean corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.setAllowCredentials(true);
corsConfiguration.setAllowedOriginPatterns(Collections.singletonList(CorsConfiguration.ALL));
corsConfiguration.addAllowedHeader(CorsConfiguration.ALL);
corsConfiguration.addAllowedMethod(CorsConfiguration.ALL);
source.registerCorsConfiguration("/**", corsConfiguration);
FilterRegistrationBean<CorsFilter> bean = new FilterRegistrationBean<>();
bean.setOrder(Integer.MIN_VALUE);
bean.setFilter(new CorsFilter(source));
bean.addUrlPatterns("/*");
return bean;
}
}

View File

@@ -37,7 +37,7 @@
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.4.5</version>
<version>2.4.13</version>
<type>pom</type>
<scope>import</scope>
</dependency>