Spring CloudeAlibaba+Nacos架构中gateway跨域解决
gateway跨域解决架构为SpringCloudAlibaba+Nacos+Gatewary,springboot版本2.2.4.RELEASE父工程pom.xnl父工程不要引入start-web的包gateway pom.xml如果父工程未引入start-web的包,这里就无需忽略<dependencies><!-- Spring Boot Begin --><d
·
gateway跨域解决
架构为SpringCloudAlibaba+Nacos+Gatewary,springboot版本2.2.4.RELEASE
父工程pom.xnl
父工程不要引入start-web的包
gateway pom.xml
如果父工程未引入start-web的包,这里就无需忽略
<dependencies>
<!-- Spring Boot Begin -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Spring Boot End -->
<!-- Spring Cloud Begin -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- Spring Cloud End -->
<!-- Commons Begin -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
<!-- Commons End-->
</dependencies>
Nacos配置文件中添加跨域设置,这里是配置文件配置的,比较方便
微服务模块就不需要使用@CrossOrigin,否则会起冲突
gateway:
globalcors:
corsConfigurations:
'[/**]':
allowedOrigins: "*"
allowedMethods: "*"
allowedHeaders: "*"
更多推荐
已为社区贡献1条内容
所有评论(0)