[monitor] 后台跨域支持,升级springboot-2.4.13
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
2
pom.xml
2
pom.xml
@@ -37,7 +37,7 @@
|
|||||||
<!-- Import dependency management from Spring Boot -->
|
<!-- Import dependency management from Spring Boot -->
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-dependencies</artifactId>
|
<artifactId>spring-boot-dependencies</artifactId>
|
||||||
<version>2.4.5</version>
|
<version>2.4.13</version>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|||||||
Reference in New Issue
Block a user