Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Spring Cloud Blog

一款基于 Spring Cloud Alibaba & Spring Boot 构建的微服务博客项目

Spring Boot Spring Cloud Spring Cloud Alibaba Java Maven MySQL Nginx


📝 项目简介

spring-cloud-blog 是一个采用前后端分离架构的现代化博客平台。后端采用微服务架构,基于 Spring Cloud Alibaba 全家桶实现,包含了用户管理、博客管理、API网关等核心功能模块。


🚀 核心技术栈

技术 名称与版本
核心框架 Spring Boot 3.1.6, Spring Cloud 2022.0.3
微服务治理 Spring Cloud Alibaba 2022.0.0.0-RC2
服务注册与发现 Nacos
配置中心 Nacos
API 网关 Spring Cloud Gateway
服务间通信 Spring Cloud OpenFeign
数据库 MySQL 8.0.33
ORM 框架 MyBatis-Plus 3.5.5
缓存 Redis
消息队列 RabbitMQ
认证方案 JWT (JSON Web Tokens)
开发语言 Java 17
构建工具 Maven
前后端分离 Nginx

🏛️ 项目架构

项目采用模块化的微服务架构,主要包含以下几个核心服务:

  • gateway-service (端口: 10030)
    • API 网关服务: 统一的请求入口,负责请求路由、转发和权限校验。
  • user-info-service
    • 用户信息服务: 负责处理用户注册、登录、信息查询等功能。
  • blog-info-service
    • 博客信息服务: 负责博客文章的增、删、改、查 (CRUD) 操作。
  • blog-common
    • 公共模块: 存放项目通用的工具类、实体类、异常处理和通用配置。

模块结构

spring-cloud-blog
├── 📂 blog-common               # 公共工具和依赖模块
├── 📂 blog-info                 # 博客管理模块父工程
│   ├── 📂 blog-info-api         # 博客服务对外暴露的 Feign 接口和 DTO
│   └── 📂 blog-info-service     # 博客服务的具体实现
├── 📂 user-info                 # 用户管理模块父工程
│   ├── 📂 user-info-api         # 用户服务对外暴露的 Feign 接口和 DTO
│   └── 📂 user-info-service     # 用户服务的具体实现
└── 📂 gateway-service           # API 网关服务

✨ 主要功能

  • 用户模块:
    • ✅ 用户登录与注册功能。
    • ✅ 基于 JWT 的无状态认证机制。
  • 博客模块:
    • ✅ 博客文章的发布、更新、删除。
    • ✅ 查看博客列表及文章详情。
  • 微服务治理:
    • ✅ 使用 Nacos 实现服务的自动注册与发现。
    • ✅ 使用 Spring Cloud Gateway 进行统一的流量转发与管理。
    • ✅ 使用 OpenFeign 实现服务间的声明式远程调用。

🛠️ 快速开始

环境准备

在启动项目之前,请确保您的环境中已安装并运行以下软件:

  • JDK 17+
  • Maven 3.5+
  • MySQL 8.0+
  • Nacos Server 2.x
  • Redis
  • RabbitMQ
  • Nginx-1.28.0

步骤

  1. 克隆项目到本地

    git clone <your-repository-url>
    cd spring-cloud-blog
  2. 配置环境

    • 启动 Nacos、MySQL、Redis 和 RabbitMQ 服务。
    • 根据您的环境,修改 user-info-service 和 blog-info-service 模块下的 application.yml 文件,配置正确的数据库、Nacos、Redis 和 RabbitMQ 连接信息。
    • 修改 gateway-service 的 application.yml 文件,配置正确的 Nacos 地址。
  3. 构建项目 在项目根目录 spring-cloud-blog 下运行 Maven 命令进行打包:

    mvn clean install
  4. 启动服务 为了确保服务能正常注册和调用,请按照以下顺序启动各个微服务:

    1. user-info-service
    2. blog-info-service
    3. gateway-service

    您可以通过 IDE 直接运行每个服务的 *Application.java 启动类,或者使用 java -jar 命令来启动打包好的 jar 文件。


🌐 API 接口概览

所有外部请求都应通过 API 网关 http://localhost:10030 进行访问。

用户服务 (路由前缀: /user)

请求方法 路径 描述
POST /user/login 用户登录
POST /user/register 用户注册
GET /user/getUserInfo 根据用户ID获取用户信息
GET /user/getAuthorInfo 根据博客ID获取作者信息

博客服务 (路由前缀: /blog)

请求方法 路径 描述
GET /blog/getList 获取博客文章列表
GET /blog/getBlogDeatail 根据ID获取博客详情
POST /blog/addBlog 新增博客 (需要认证)
POST /blog/updateBlog 更新博客 (需要认证)
GET /blog/deleteBlog 删除博客 (需要认证)

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages