"*" since that cannot be set on the "Access-Control-Allow-Origin" response header. To allow credentials to a set of origins, list them explicitly or consider using "allowedOriginPatterns" instead.
@ComponentScan( 多个包的时候会报错
因为需要扫描 com.noah2021 这个包,所以配置了
@ComponentScan({"com.**"})
这样配置就报错了
但是以下配置是可以的,但是com.noah2021 就扫描不进去了
@ComponentScan({"com.zucc.whatRubbish.**","com.v.im"})
@EntityScan({"com.zucc.whatRubbish", "com.v.im.user","com.noah2021"}) //不在一个项目中需要配置
@EnableJpaRepositories(basePackages = { "com.zucc.whatRubbish","com.v.im.user" }) //这个是repository的包的路径
//————————————————
// 版权声明:本文为CSDN博主「Mr_ZhangAdd」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
// 原文链接:https://blog.csdn.net/Mr_ZhangAdd/article/details/102547396
public class ImApplication {
跨域配置在 com\v\im\conf\SimpleCORS.java
因为只要不扫描 com.noah2021 跨域的配置就是正常的,因此应该可以认为此配置代码是正确的吧。。
package com.v.im.conf;
//import javafx.beans.binding.When;
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.ArrayList;
import java.util.List;
//CORS跨域配置类
@Configuration
public class SimpleCORS {
// 这配置没有问题吗 但是有 com.noah2021 就会有问题 寄
private CorsConfiguration corsConfig() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOriginPattern("*");
// corsConfiguration.addAllowedOrigin();
// corsConfiguration. setAllowedOriginPatterns("*");
List<String>allows=new ArrayList<>();
allows.add("*");
// 是不是不要配置了 但是不配置还是会报错
// Caused by: java.lang.IllegalArgumentException: When allowCredentials is true, allowedOrigins cannot contain the special value "*" since that cannot be set on the "Access-Control-Allow-Origin" response header. To allow credentials to a set of origins, list them explicitly or consider using "allowedOriginPatterns" instead.
corsConfiguration. setAllowedOriginPatterns(allows);
corsConfiguration.addAllowedHeader("*");
corsConfiguration.addAllowedMethod("*");
corsConfiguration.setAllowCredentials(true);
corsConfiguration.setMaxAge(3600L);
return corsConfiguration;
}
@Bean
public CorsFilter corsFilter() {
System.out.println("corsFilter");
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", corsConfig());
return new CorsFilter(source);
}
}