单体项目到微服务升级
配置类不用动,主要还是对以来进行修改
无非下面两个步骤:网关排除并引入依赖,各个服务修改yml
这里先把网关的yml统一下
katool:
security:
mode: single
core:
token-header: "Authorization" ## 这个适用于标识token存放在哪个header中
同时每个服务的主函数上面打一个注解@EnableKaSecurityAuthCenter
即可
@ConfigurationPropertiesScan(basePackages = "cn.katool.security")
@SpringBootApplication
@EnableKaSecurityAuthCenter
public class ZuulSimpleDemoApplication {
public static void main(String[] args) {
SpringApplication.run(ZuulSimpleDemoApplication.class, args);
}
}
适配SpringCloudGateWay
具体的demo,可以看看git
网关排除依赖
<dependency>
<groupId>cn.katool.security.demo.gateway</groupId>
<artifactId>katool-security-gateway-simple-demo-core</artifactId>
<version>1.0.0-ALPHA</version>
<exclusions>
<exclusion>
<groupId>cn.katool.security</groupId>
<artifactId>katool-security-spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
网关引入依赖
<!--引入SpringCloudGateWay对应的Starter-->
<dependency>
<groupId>cn.katool.security</groupId>
<artifactId>katool-security-gateway-spring-cloud-gateway-starter</artifactId>
<version>1.0.0.SNAPSHOT</version>
</dependency>
各个服务修改application.yaml
这里可以统一用个配置中心吧
katool:
security:
mode: gateway ## 选择通过SpringCloudGateWay进行鉴权,其实选择Zuul也是可以的,但是gateway我们更建议
core:
token-header: "Authorization"