Spring boot 2.3.* to Spring boot 2.4.* Spring Cloud 2020.0.0
bootstrap.yml
pom
需引入bootstrap
依赖<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bootstrap</artifactId> </dependency>
- StackOverflow
@SpringCloudApplication
- 改为使用 @EnableDiscoveryClient @SpringBootApplication
- Example
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.openfeign.EnableFeignClients; /** * The type Example application. */ @EnableFeignClients @EnableDiscoveryClient @SpringBootApplication public class ExampleApplication { /** * The entry point of application. * * @param args the input arguments */ public static void main(String[] args) { SpringApplication.run(ExampleApplication.class, args); } }
Gateway 跨域问题
- IllegalArgumentException
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.
- 使用
allowedOriginPatterns
替代allowedOrigins
- Example
spring: cloud: gateway: globalcors: corsConfigurations: '[/**]': #允许cookies跨域 allowCredentials: true #允许向该服务器提交请求的URI,*表示全部允许,在SpringMVC中,如果设成*,会自动转成当前请求头中的Origin allowedOriginPatterns: '*' #允许提交请求的方法,*表示全部允许 allowedMethods: '*' #允许访问的头信息,*表示全部 allowedHeaders: '*' #预检请求的缓存时间(秒),即在这个时间段里,对于相同的跨域请求不会再预检了 maxAge: 18000