单体项目到微服务升级
配置类不用动,主要还是对以来进行修改
无非下面两个步骤:网关排除并引入依赖,各个服务修改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);
}
}
适配Zuul
具体的demo,可以看看git
网关排除依赖
<dependency>
<groupId>cn.katool.security.demo.gateway</groupId>
<artifactId>katool-security-zuul-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>
网关引入依赖
<!--引入Zuul对应的Starter-->
<dependency>
<groupId>cn.katool.security</groupId>
<artifactId>katool-security-gateway-zuul-starter</artifactId>
<version>1.0.0.SNAPSHOT</version>
</dependency>
各个服务修改application.yaml
这里可以统一用个配置中心吧
katool:
security:
mode: zuul ## 选择通过Zuul进行鉴权,其实选择SpringCloudGateWay也是可以的,但是Zuul我们更建议
core:
token-header: "Authorization"