config文件夹下 直接 创建CorsConfig类 粘贴以下代码
package cn.tedu.datasource.config;
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 org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration //跨域配置类
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("*")
.allowCredentials(true).maxAge(3600);
}
private CorsConfiguration corsConfig() {
CorsConfiguration corsConfigurati
cors解决跨域问题
于 2021-12-27 15:53:26 首次发布
本文介绍了如何在Spring项目中通过创建CorsConfig类并配置跨域策略来解决跨域问题。具体步骤包括添加@Configuration注解,实现WebMvcConfigurer接口,重写addCorsMappings方法,设置allowedOrigins, allowedMethods, allowCredentials和maxAge等属性,以允许所有源进行跨域请求。"
8455044,1395137,JAVA FTPClient 实现文件上传下载,"['JAVA开发', 'FTP服务', '文件处理']
摘要由CSDN通过智能技术生成