Convert Figma logo to code with AI

zhoutaoo logoSpringCloud

基于SpringCloud2.1的微服务开发脚手架,整合了spring-security-oauth2、nacos、feign、sentinel、springcloud-gateway等。服务治理方面引入elasticsearch、skywalking、springboot-admin、zipkin等,让项目开发快速进入业务开发,而不需过多时间花费在架构搭建上。持续更新中

8,671
3,867
8,671
57

Top Related Projects

Spring Cloud Alibaba provides a one-stop solution for application development for the distributed solutions of Alibaba middleware.

Integration with Netflix OSS components

77,204

mall项目是一套电商系统,包括前台商城系统及后台管理系统,基于SpringBoot+MyBatis实现,采用Docker容器化部署。 前台商城系统包含首页门户、商品推荐、商品搜索、商品展示、购物车、订单流程、会员中心、客户服务、帮助中心等模块。 后台管理系统包含商品管理、订单管理、会员管理、促销管理、运营管理、内容管理、统计报表、财务管理、权限管理、设置等模块。

一个涵盖六个专栏:Spring Boot 2.X、Spring Cloud、Spring Cloud Alibaba、Dubbo、分布式消息队列、分布式事务的仓库。希望胖友小手一抖,右上角来个 Star,感恩 1024

《史上最简单的Spring Cloud教程源码》

Quick Overview

SpringCloud is a comprehensive microservices architecture project based on Spring Cloud. It provides a complete set of microservices solutions, including service discovery, configuration management, API gateway, circuit breaker, and more. The project aims to demonstrate best practices for building and deploying microservices using Spring Cloud.

Pros

  • Offers a complete microservices ecosystem with various components integrated
  • Provides detailed documentation and examples for each module
  • Implements security features, including OAuth2 authentication and authorization
  • Includes monitoring and logging solutions for better observability

Cons

  • Some parts of the documentation are in Chinese, which may be challenging for non-Chinese speakers
  • The project is quite complex, which might be overwhelming for beginners
  • Some dependencies may be outdated and require updates
  • Limited community support compared to more popular Spring Cloud examples

Code Examples

  1. Service Registration with Eureka
@SpringBootApplication
@EnableEurekaClient
public class ServiceApplication {
    public static void main(String[] args) {
        SpringApplication.run(ServiceApplication.class, args);
    }
}

This code snippet shows how to enable Eureka client for service registration.

  1. API Gateway Configuration
spring:
  cloud:
    gateway:
      routes:
        - id: user-service
          uri: lb://USER-SERVICE
          predicates:
            - Path=/user/**

This YAML configuration demonstrates how to set up a route in the API Gateway.

  1. Circuit Breaker with Hystrix
@HystrixCommand(fallbackMethod = "fallbackMethod")
public String callService() {
    // Service call logic
}

public String fallbackMethod() {
    return "Fallback response";
}

This example shows how to use Hystrix for implementing a circuit breaker pattern.

Getting Started

  1. Clone the repository:

    git clone https://github.com/zhoutaoo/SpringCloud.git
    
  2. Navigate to the project directory:

    cd SpringCloud
    
  3. Build the project using Maven:

    mvn clean install
    
  4. Start the required services (e.g., Eureka, Config Server, Gateway):

    java -jar auth/authentication-server/target/authentication-server.jar
    java -jar gateway/gateway-web/target/gateway-web.jar
    java -jar center/eureka/target/eureka-server.jar
    
  5. Access the Eureka dashboard at http://localhost:8761 to verify service registration.

Competitor Comparisons

Spring Cloud Alibaba provides a one-stop solution for application development for the distributed solutions of Alibaba middleware.

Pros of spring-cloud-alibaba

  • Extensive integration with Alibaba Cloud services
  • Larger community and more frequent updates
  • Comprehensive documentation and examples

Cons of spring-cloud-alibaba

  • Steeper learning curve due to more complex features
  • Potential vendor lock-in with Alibaba Cloud services

Code Comparison

SpringCloud:

@SpringBootApplication
@EnableDiscoveryClient
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

spring-cloud-alibaba:

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

Key Differences

  • spring-cloud-alibaba offers more advanced features like Sentinel for circuit breaking and flow control
  • SpringCloud focuses on a simpler, more straightforward implementation of microservices
  • spring-cloud-alibaba provides better support for distributed configuration management with Nacos

Use Cases

  • SpringCloud: Ideal for smaller projects or teams new to microservices architecture
  • spring-cloud-alibaba: Better suited for large-scale applications, especially those leveraging Alibaba Cloud services

Community and Support

  • spring-cloud-alibaba has a larger user base and more active development
  • SpringCloud offers a simpler codebase, making it easier for contributors to understand and modify

Integration with Netflix OSS components

Pros of Spring Cloud Netflix

  • Official Spring Cloud project with extensive documentation and community support
  • Comprehensive set of tools for building microservices, including service discovery, load balancing, and circuit breakers
  • Seamless integration with other Spring Cloud components

Cons of Spring Cloud Netflix

  • Larger footprint and potentially higher resource consumption
  • More complex configuration and setup process
  • Some components (e.g., Hystrix) are in maintenance mode

Code Comparison

SpringCloud:

@SpringBootApplication
@EnableDiscoveryClient
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

Spring Cloud Netflix:

@SpringBootApplication
@EnableEurekaClient
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

The main difference in the code is the use of @EnableDiscoveryClient in SpringCloud versus @EnableEurekaClient in Spring Cloud Netflix. SpringCloud uses a more generic annotation, while Spring Cloud Netflix specifically enables Eureka for service discovery.

Both projects aim to simplify microservices development, but Spring Cloud Netflix offers a more comprehensive and widely adopted solution, while SpringCloud provides a lighter alternative with potentially easier setup and configuration.

77,204

mall项目是一套电商系统,包括前台商城系统及后台管理系统,基于SpringBoot+MyBatis实现,采用Docker容器化部署。 前台商城系统包含首页门户、商品推荐、商品搜索、商品展示、购物车、订单流程、会员中心、客户服务、帮助中心等模块。 后台管理系统包含商品管理、订单管理、会员管理、促销管理、运营管理、内容管理、统计报表、财务管理、权限管理、设置等模块。

Pros of mall

  • More comprehensive e-commerce functionality, including product management, order processing, and user systems
  • Extensive documentation and deployment guides, making it easier for developers to understand and implement
  • Active community with frequent updates and contributions

Cons of mall

  • Larger codebase and more complex architecture, potentially harder to grasp for beginners
  • Focused specifically on e-commerce, less flexible for other types of applications
  • Heavier resource requirements due to its comprehensive nature

Code Comparison

mall:

@ApiOperation("添加商品")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult create(@RequestBody PmsProductParam productParam) {
    int count = productService.create(productParam);
    if (count > 0) {
        return CommonResult.success(count);
    } else {
        return CommonResult.failed();
    }
}

SpringCloud:

@PostMapping("/product")
public ResponseEntity<Product> createProduct(@RequestBody Product product) {
    Product savedProduct = productService.save(product);
    return ResponseEntity.ok(savedProduct);
}

The mall project provides more detailed API documentation and uses a custom result object, while SpringCloud uses standard Spring ResponseEntity. Mall's code is more tailored for e-commerce, whereas SpringCloud's is more generic.

一个涵盖六个专栏:Spring Boot 2.X、Spring Cloud、Spring Cloud Alibaba、Dubbo、分布式消息队列、分布式事务的仓库。希望胖友小手一抖,右上角来个 Star,感恩 1024

Pros of SpringBoot-Labs

  • More comprehensive coverage of Spring Boot topics and features
  • Regularly updated with new examples and technologies
  • Better organized structure with separate modules for different concepts

Cons of SpringBoot-Labs

  • Lacks focus on microservices architecture compared to SpringCloud
  • May be overwhelming for beginners due to the large number of examples
  • Less emphasis on production-ready configurations

Code Comparison

SpringBoot-Labs:

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

SpringCloud:

@SpringCloudApplication
@EnableFeignClients
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

The main difference in the code snippets is the use of @SpringCloudApplication and @EnableFeignClients annotations in SpringCloud, which are specific to microservices architecture and inter-service communication. SpringBoot-Labs uses the standard @SpringBootApplication annotation, focusing on general Spring Boot applications.

SpringBoot-Labs provides a wider range of examples and topics related to Spring Boot, making it suitable for learning various aspects of the framework. On the other hand, SpringCloud is more focused on building microservices-based applications using Spring Cloud components.

《史上最简单的Spring Cloud教程源码》

Pros of SpringCloudLearning

  • More beginner-friendly with step-by-step tutorials and explanations
  • Covers a wider range of Spring Cloud components and features
  • Regularly updated with newer Spring Cloud versions

Cons of SpringCloudLearning

  • Less comprehensive in terms of a complete microservices architecture
  • Lacks advanced security implementations and configurations
  • Doesn't include as many real-world scenarios or production-ready examples

Code Comparison

SpringCloudLearning:

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class, args);
    }
}

SpringCloud:

@SpringBootApplication
@EnableEurekaServer
@EnableResourceServer
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class EurekaServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class, args);
    }
}

The SpringCloud example includes additional security-related annotations, demonstrating a more production-ready approach to service discovery implementation.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Build Status License codecov

根据前期的使用和反馈,目前将脚手架整体进行了重构,发布了新的框架 Opensabre,当前仓库代码暂停维护,请使用新版

开放源码: https://github.com/opensabre/opensabre-framework

在线文档: 在线文档

进群交流: 进群交流

架构特点

1. 统一Restful的响应报文,controll返回原始类型即可,无需手动包装,简化代码,可读性更好。

2. 统一异常处理,封装了基本的异常的响应,如参数检验、文件上传等。简化代码,更方便扩展。

3. 默认集成Swagger 3.0 API文档,方便接口文档的传递、协作与调试。

4. 标准化WEB对象传递/转换/使用,方便统一开发风格,简化操作。

5. 框架/环境等元数据自动收集注册至properties和Nacos,方便系统运行时作为扩展判断,信息处理。

6. 系统启动时自动收集所有Restful url注册到权限资源,方便进行集中权限管理和授权使用。

7. 多机房/双活路由负载扩展支持,自定义路由和负载规则,更灵活、可控。

8. 默认引入spring validation,并扩展枚举、手机号等常用校验注解。

9. 默认引入日志trace、actuator等组件,统一日志打印格式。

10. 整体系统化为三层,framework框架、framework组件、基础应用,层次更清楚,结构更合理。

11. 配置中心,划分框架全局配置与应用配置(熔断降级、网关路由),规划中。

快速开始

先决条件

首先本机先要安装以下环境,建议先学习了解springboot和springcloud基础知识。

开发环境搭建

linux和mac下可在项目根目录下执行 ./install.sh 快速搭建开发环境。如要了解具体的步骤,请看如下文档。

具体步骤如下:

  1. 克隆代码库: git clone https://github.com/zhoutaoo/SpringCloud.git

  2. 安装公共库到本地仓库:

mvn -pl ./common,./auth/authentication-client install

  1. 生成ide配置: mvn idea:idea或mvn eclipse:eclipse 并导入对应的ide进行开发,IDE安装lombok插件(很重要,否则IDE会显示编译报错)

编译 & 启动

  • 1.启动基础服务:进入docker-compose目录,执行docker-compose -f docker-compose.yml up 或单个启动docker-compose up 服务名, 服务名如下

在启动应用之前,需要先启动数据库、缓存、MQ等中间件,可根据自己需要启动的应用选择启动某些基础组件,一般来说启动mysql、redis、rabbitmq即可,其它组件若有需要,根据如下命令启动即可。

该步骤使用了docker快速搭建相应的基础环境,需要你对docker、docker-compose有一定了解和使用经验。也可以不使用docker,自行搭建以下服务即可。

服务服务名端口备注
数据库mysql3306目前各应用共用1个实例,各应用可建不同的database
KV缓存redis6379目前共用,原则上各应用单独实例
消息中间件rabbitmq5672共用
注册与配置中心nacos8848启动和使用文档
日志收集中间件zipkin-server9411共用
搜索引擎中间件elasticsearch9200共用
日志分析工具kibana5601共用
数据可视化工具grafana3000共用
  • 2.创建数据库及表

只有部分应用有数据库脚本,若启动的应用有数据库的依赖,请初使化表结构和数据后再启动应用。

docker方式脚本初使化:进入docker-compose目录,执行命令 docker-compose up mysql-init

子项目脚本

路径一般为:子项目/db

如:auth/db 下的脚本,请先执行ddl建立表结构后再执行dml数据初使化

应用脚本

路径一般为:子项目/应用名/src/main/db

如:demos/producer/src/main/db 下的脚本

  • 3.启动应用

根据自己需要,启动相应服务进行测试,cd 进入相关应用目录,执行命令: mvn spring-boot:run

以下应用都依赖于rabbitmq、nacos,启动服务前请先启动mq和注册中心

服务分类服务名依赖基础组件简介应用地址文档
centerbus-server消息中心http://localhost:8071消息中心文档
sysadminorganizationmysql、redis用户组织应用http://localhost:8010待完善
authauthorization-servermysql、organization授权服务http://localhost:8000权限服务简介 、授权server文档
authauthentication-servermysql、organization认证服务http://localhost:8001认证server文档
authauthentication-client无认证客户端jar包引入
gatewaygateway-webredisWEB网关http://localhost:8443WEB网关简介 WEB网关文档
gatewaygateway-adminmysql、redis网关管理http://localhost:8445网关管理后台文档
monitoradmin总体监控http://localhost:8022
  • 4.案例示意图

以下是一个用户访问的的示意图,用户请求通过gateway-web应用网关访问后端应用,通过authorization-server应用登陆授权换取token,请求通过authentication-server应用进行权限签别后转发到"您的业务应用"中

authorization-server为授权应用,启动前请初使化好数据库,授权Server文档。

authentication-server为签权应用,若有新增接口,请初使化相关权限数据到resource表中。

gateway-admin可动态调整gateway-web的路由策略,测试前请先配置网关的转发策略,路由策略配置。

示意图

  • 6.前端项目

确确保gateway-admin、gateway-web、organization、authorization-server、authentication-server服务启动,然后启动

前端项目(该项目目前还在开发中)

大家启动如有问题,可以先到这里看看,也可以加入交流群

常见问题

测试

运行 mvn test 启动测试.

架构与开发

架构

开发指南

开发指南

功能与特性

功能预览

用户管理 用户管理

角色管理 角色管理

服务容错 服务容错

API文档 API文档

组织架构管理 组织架构管理

基础服务

服务使用技术进度备注
注册中心Nacos✅
配置中心Nacos✅
消息总线SpringCloud Bus+Rabbitmq✅
灰度分流OpenResty + lua🏗
动态网关SpringCloud Gateway✅多种维度的流量控制(服务、IP、用户等),后端可配置化🏗
授权认证Spring Security OAuth2✅Jwt模式
服务容错SpringCloud Sentinel✅
服务调用SpringCloud OpenFeign✅
对象存储FastDFS/Minio🏗
任务调度Elastic-Job🏗
分库分表Mycat🏗
数据权限🏗使用mybatis对原查询做增强,业务代码不用控制,即可实现。

平台功能

服务使用技术进度备注
用户管理自开发✅用户是系统操作者,该功能主要完成系统用户配置。
角色管理自开发✅角色菜单权限分配、设置角色按机构进行数据范围权限划分。
菜单管理自开发🏗配置系统菜单,操作权限,按钮权限标识等。
机构管理自开发🏗配置系统组织机构,树结构展现,可随意调整上下级。
网关动态路由自开发🏗网关动态路由管理

开发运维

服务使用技术进度备注
代码生成🏗前后端代码的生成,支持Vue
测试管理🏗
文档管理Swagger2✅
服务监控Spring Boot Admin✅
链路追踪SkyWalking✅
操作审计🏗系统关键操作日志记录和查询
日志管理ES + Kibana、Zipkin✅
监控告警Grafana✅

更新日志

2019-10-18:

1.使用nacos替代eureka为服务的注册中心

2.使用nacos替代apollo为服务的配置中心

3.引入使用sentinel替换掉hystrix,引入sentinel-dashboard

4.使用jetcache作两级缓存,优化缓存性能

5.网关启动时加载数据库中的路由到redis缓存

6.其它已知bug修复

联系交流

加入贡献代码

请入群 请戳这里 加群主微信。

请作者喝饮料

如果你觉的有帮助到您,可以请作者喝饮料,这样更有动力,谢谢。

学习交流

EMail:zhoutaoo@foxmail.com

群1、2、3、4、5、6、7、8、9已满,请加群10,加群请戳这里

此些群仅为技术交流群,请大家不要讨论政治、发广告等与技术无关的东西。大家如若有问题可以在群里直接发问,我会抽空答复。

请大家问问题时尽量描述清楚背景与问题关键信息,描述的越清楚越容易得到答案。也更容易判断问题可能点,节省判断的时间,而不用来回问答。

同时也鼓励群友们积极回复已知的问题,大家相互帮助共同成长。如有bug或新需求也可以直接提交issue到github,我会酌情处理。

如果你发现你的问题很久都没有人答复,那很有可能就是问题描述的不够清楚,别人无法回复。

**问问题的三要素**

  1. 说明背景,使用了哪个模块,要做什么?

  2. 怎么输入或操作的得到了什么结果? 截图,日志

  3. 哪里不明白或有什么疑问 ?

Stargazers over time

Stargazers over time