Recommend an awesome SpringCloud scaffolding project

I took a private job before, and I searched for a long time on the Internet and could not find a suitable framework. Either the version is low and no one is maintained, or the components are highly interdependent. So I built a new spingCloud framework by myself, all components in it are pluggable, and multiple components are integrated for everyone to choose, which one you like to use

1. System Architecture Diagram

2. Quick Start

1. Start nacos locally: http://127.0.0.1:8848

sh startup.sh -m standalone
复制代码

2. Start sentinel locally: http://127.0.0.1:9000

nohup java -Dauth.enabled=false -Dserver.port=9000 -jar sentinel-dashboard-1.8.1.jar &
复制代码

3. Start zipkin locally: http://127.0.0.1:9411/

nohup java -jar zipkin-server-2.23.2-exec.jar &
复制代码

3. Project Overview

  • springboot+springcloud
  • Registration Center: nacos
  • gateway: gateway
  • RPC:feign

The following are pluggable functional components

  • Flow control fuse downgrade: sentinel
  • Full link tracking: sleth+zipkin
  • Distributed transaction: seata
  • Encapsulated functional modules: global exception handling, log output print persistence, multiple data sources, authentication and authorization modules, zk (distributed lock and subscriber mode)
  • maven: realize multi-environment packaging and push images directly to docker private server.

This project integrates various components in the springcloud system. and integration configuration instructions. At the same time, the functional packages and toolkits that you usually use are integrated into the most modules. It can avoid forgetting some technical points after not using them for a long time.

On the other hand, the version of springboot springcloud and springcloud-alibaba is now iterating faster and faster.

In order to ensure that our encapsulation and integration method still works normally in the new version, we need to use this project to carry out the adaptation experiment of the latest version. In this way, the functional modules in the project can be assembled in the project faster.

4. Project Preview

V. Description of the new business engineering module

Because springboot follows the principle of convention over configuration. Therefore, the package paths where all the classes in this project are located are under com.cloud.base.

If the newly created business project specifies the specified base package path, you need to add a package scan annotation to the startup class to add all classes under com.cloud.base to the scan scope.

@ComponentScan(basePackages = "com.cloud.base")
复制代码

If you can continue to use com.cloud.base, the convention is to put the startup class in this path.

6. Module division

父工程:

cloud-base - 版本依赖管理  <groupId>com.cloud</groupId>
|
|--common - 通用工具类和包  <groupId>com.cloud.common</groupId>
|   |
|   |--core-common  通用包 该包包含了SpringMVC的依赖,会与WebFlux的服务有冲突
|   |
|   |--core-exception 自定义异常和请求统一返回类
|
|--dependency - 三方功能依赖集合 无任何实现 <groupId>com.cloud.dependency</groupId>
|   |
|   |--dependency-alibaba-cloud 关于alibaba-cloud的依赖集合
|   |
|   |--dependency-mybatis-tk 关于ORM mybatis+tk.mybatis+pagehelper的依赖集合
|   |
|   |--dependency-mybatis-plus 关于ORM mybatis+mybatis—plus+pagehelper的依赖集合
|   |
|   |--dependency-seata 关于分布式事务seata的依赖集合
|   |
|   |--dependency-sentinel 关于流控组件sentinel的依赖集合
|   |
|   |--dependency-sentinel-gateway 关于网关集成流控组件sentinel的依赖集合(仅仅gateway网关使用该依赖)
|   |
|   |--dependency-sleuth-zipkin 关于链路跟踪sleuth-zipkin的依赖集合
|
|--modules - 自定义自实现的功能组件模块 <groupId>com.cloud.modules</groupId>
|   |
|   |--modules-logger 日志功能封装
|   |
|   |--modules-multi-datasource 多数据功能封装
|   |
|   |--modules-lh-security 分布式安全授权鉴权框架封装
|   |
|   |--modules-youji-task 酉鸡-分布式定时任务管理模块
|   |
|
|   
|   
| 以下是独立部署的应用 以下服务启动后配合前端工程使用 (cloud-base-angular-admin)
|
|--cloud-gateway  应用网关
|
|--authorize-center 集成了modules-lh-security 的授权中心,提供统一授权和鉴权
|   
|--code-generator 代码生成工具
|
|--user-center 用户中心 提供用户管理和权限管理的相关服务
|
|--youji-manage-server 集成了modules-youji-task 的定时任务管理服务端
复制代码

Seven, version instructions

<springboot.version>2.4.2</springboot.version>
<springcloud.version>2020.0.3</springcloud.version>
<springcloud-alibaba.version>2021.1</springcloud-alibaba.version>
复制代码

Eight, multi-environment packaging instructions

Add configuration files for different environments in the resources resource directory of modules that need to be packaged independently

application-dev.yml
application-test.yml
application-prod.yml
复制代码

Modify application.yml

spring:
  profiles:
    active: @profileActive@
复制代码

Add the packaging configuration to the pom file under the module that needs to be packaged independently.

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>${springboot.version}</version>
            <configuration>
                <fork>true</fork>
                <addResources>true</addResources>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <configuration>
                <delimiters>
                    <delimiter>@</delimiter>
                </delimiters>
                <useDefaultDelimiters>false</useDefaultDelimiters>
            </configuration>
        </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

<profiles>
    <profile>
        <id>dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <profileActive>dev</profileActive>
        </properties>
    </profile>
    <profile>
        <id>test</id>
        <properties>
            <profileActive>test</profileActive>
        </properties>
    </profile>
    <profile>
        <id>prod</id>
        <properties>
            <profileActive>prod</profileActive>
        </properties>
    </profile>
</profiles>
复制代码

mvn package command

# 打开发环境
mvn clean package -P dev -Dmaven.test.skip=ture
# 打测试环境
mvn clean package -P test -Dmaven.test.skip=ture
# 打生产环境
mvn clean package -P prod -Dmaven.test.skip=ture
复制代码

9. Build a Docker image

Integrate the dockerfile plug-in, which can directly build the jar package into a docker image and push it to the remote warehouse

Add plugin dependencies

<!-- docker image build -->
<plugin>
    <groupId>com.spotify</groupId>
    <artifactId>dockerfile-maven-plugin</artifactId>
    <version>1.4.10</version>
    <executions>
        <execution>
            <id>default</id>
            <goals>
                <!--如果package时不想用docker打包,就注释掉这个goal-->
                <!--                        <goal>build</goal>-->
                <goal>push</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <repository>49.232.166.94:8099/example/${project.artifactId}</repository>
        <tag>${profileActive}-${project.version}</tag>
        <username>admin</username>
        <password>Harbor12345</password>
        <buildArgs>
            <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
        </buildArgs>
    </configuration>
</plugin>
复制代码

Add Dockerfile in the same directory as pom.xml

FROM registry.cn-hangzhou.aliyuncs.com/lh0811/lh0811-docer:lh-jdk1.8-0.0.1
MAINTAINER lh0811
ADD  ./target/${JAR_FILE} /opt/app.jar
RUN chmod +x /opt/app.jar
CMD java -jar /opt/app.jar
复制代码

10. Obtaining the source code

Source code and development notes

Guess you like

Origin juejin.im/post/7100457917115007013