首先在gateway的pom.xml文件下增加:
//hutool工具类 因为没传common类
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
</dependency>
// 热部署
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
在getway的config文件下生成LoginMemberFilter类(过滤器): 请求时带上token,返回时校验返回码是不是401
package com.jiawa.train.gateway.config; import com.jiawa.train.gateway.util.JwtUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cloud.gateway.filter.GatewayFilterChain; import org.springframework.cloud.gateway.filter.GlobalFilter; import org.