权限中心工程结构
auth-client为基础model,包含数据传输对象POJO,以及对外提供的微服务接口。
auth-server为项目启动入口,它依赖于auth-client。
依赖pom
auth-client:
base里包含所有springboot分布式开发依赖包。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>cn.kite</groupId>
<artifactId>auth-center</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>cn.kite</groupId>
<artifactId>auth-client</artifactId>
<version>1.0-SNAPSHOT</version>
<name>auth-client</name>
<dependencies>
<dependency>
<groupId>cn.kite</groupId>
<artifactId>base</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
auth-server:
依赖auth-client。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.kite</groupId>
<artifactId>auth-center</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>cn.kite</groupId>
<artifactId>auth-server</artifactId>
<version>1.0-SNAPSHOT</version>
<name>auth-server</name>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>cn.kite</groupId>
<artifactId>auth-client</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
项目配置
application.yml:
spring:
profiles:
active: dev
application:
name: auth-center
#配置404路径进入全局异常拦截
mvc:
throw-exception-if-no-handler-found: true
resources:
add-mappings: false
server:
port: 8011
mybatis:
mapperLocations: classpath*:/mapper/*.xml
configuration:
# 配置下划线自动转驼峰
map-underscore-to-camel-case: true
application-dev.yml:
spring:
datasource:
url: jdbc:mysql://127.0.0.1:3306/kite_blog?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&noAccessToProcedureBodies=true&tinyInt1isBit=false&useSSL=false
driver-class-name: com.mysql.jdbc.Driver
password: 123456
username: root
redis:
host: 127.0.0.1
port: 6379
password: 123456
database: 0
timeout: 5000
cloud:
nacos:
server-addr: localhost:8848
discovery:
namespace: 6c72c480-298e-4cf5-9947-9062829567d0
config:
namespace: 6c72c480-298e-4cf5-9947-9062829567d0
logging:
level:
feign: debug
cn.kite.*.mapper: debug
项目基础接口
主要就是提供一个token验证接口,用于其他服务调用,验证用户登录token是否有效。
对外提供接口
主要用于博客中心、用户中心调这个接口,验证登录token是否有效。
@FeignClient(name = "auth-center", fallback = AuthClientCallback.class, path = "/auth")
public interface AuthClient {
/**
* 验证登录token
*/
@PostMapping("/valid")
BaseResponse<LoginUserInfo> valid(@RequestBody AuthValidReqVO reqVO);
}
其它业务代码不贴了。
用户中心和博客中心
项目搭建与权限中心差不多,都是在主项目下新建对应的model。项目结构也是分为*-client和*-server两部分。
项目地址
https://gitee.com/AfterTheFall/springcloud-kite-blog