springblade微服务代码生成的微服务管理的详细教程

目前微服务作为分段式、高并发、负载均衡、服务注册、权限认证、聚合文档、熔断保护等机制合为一体的全新分布式服务,功能显而易见,在目前的开发市场中占据很大的优势,如何学习微服务,对程序员来说至关重要(学不会,可能饭碗不保!)springblade 是springcloude 的转化,也可以理解为加强版!,而且也是属于开源项目。我们首先需要再我们的github中下载一个源码

导入到我们的idea中;如下图所示:

执行doc包下边的sql文件:只需要执行后边两个就可以

然后创建我们所需要生成的tb_student表:(这里注意我们的表名必须以tb_开头,不然生成配置过程中,会报错。)

这里千万不要忘记给我们的字段和表添加注释!

接下来再idea中创建我们的服务,

blade里边的微服务默认放到blade-service里边,再blade-service里边放上我们

环境准备方面(具体安装下载可以直接查找csdn,安装比较简单)

后端除了基本的环境设置外还需要准备:redeis 缓存

nacos 服务注册

sentinel 高可用流量控制(附加服务,可以不准备也行)

前端环境准备:node

首先启动本地的nacos服务:双击安装好的nacos里边bin下的stratup,启动成功的样子如下图

然后启动我们的redis;后端环境部署完成之后就可以启动我们的项目了

首先,我们需要启动的基础项目为 下图所示:

基础项目启动之后,我们是需要用到他的代码生成的,所以我们需要额外启动我们的blade-develop模块;启动之后所有服务如下图:

然后我们就可以启动我们的前端了,前端默认的网关地址为geteway的地址80端口:

启动前端

运行之后我们打开地址路径:

登录之后页面如下图所示:

点击研发工具 里边的数据源管理:选择我们的使用的数据源,我这边使用的是mysql的数据源。

点击编辑:修改我们的mysql的账户跟密码

配置好数据源之后,我们点击数据模型设计,

模型备注可以不写,如果添加的有备注,其它的必填项会自动生成;

然后点击研发工具里边的代码生成,点击新增,将我们刚才数据配置过的tb_student新增上去:

这里注意服务名,一定要给你创建的服务名保持一致,不要后边的方法测试会报404.因为blade默认是将项目名挡住服务名进行注册的;

blade 加强了生成配置,可以直接将我们的代码直接放到我们所创建的服务上边;在我们的生成配置中可以直接设置路径;我们直接将我们创建好的项目的根路径地址填写上去;‘

然后点击代码生成:

然后查看我们的idea中的前后端代码是否生成到指定的位置:

然后我们需要配置一下我们的resources;将blade-desk的resource文件直接复制到blade-student下,更改一下端口号

然后就是编写我们这个模块的启动类了,我们可以直接将blade-desk的启动类复制过来就可以;

具体启动类的代码如下:

/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.student;

import org.springblade.common.constant.LauncherConstant;
import org.springblade.core.cloud.client.BladeCloudApplication;
import org.springblade.core.launch.BladeApplication;
import org.springblade.core.launch.constant.AppConstant;

/**
 * Desk启动器
 *
 * @author Chill
 */
@BladeCloudApplication
public class StudentApplication {

    public static void main(String[] args) {
        BladeApplication.run(LauncherConstant.APPLICATION_STUDENT_NAME, StudentApplication.class, args);
    }

}

因为blade微服务中生成有聚合文档,所以我们可以直接调式直接在聚合文档中调试:(不需要再postman中进行调式了)

启动我们的blade-swagger服务前需要添加swagger依赖

具体的student依赖如下所示:

<?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>
        <artifactId>blade-service</artifactId>
        <groupId>org.springblade</groupId>
        <version>3.0.1.RELEASE</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>blade-student</artifactId>

    <name>${project.artifactId}</name>
    <version>${bladex.project.version}</version>
    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>org.springblade</groupId>
            <artifactId>blade-core-boot</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springblade</groupId>
            <artifactId>blade-starter-excel</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springblade</groupId>
            <artifactId>blade-starter-swagger</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springblade</groupId>
            <artifactId>blade-system-api</artifactId>
            <version>${bladex.project.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>dockerfile-maven-plugin</artifactId>
                <configuration>
                    <username>${docker.username}</username>
                    <password>${docker.password}</password>
                    <repository>${docker.registry.url}/${docker.namespace}/${project.artifactId}</repository>
                    <tag>${project.version}</tag>
                    <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
                    <buildArgs>
                        <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
                    </buildArgs>
                    <skip>false</skip>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

添加好依赖之后我们需要将我们的student模块配置到我们的swagger文档当中:

然后配置好之后先启动我们的blade-student,然后启动我们的blade-swagger;

swagger聚合文档的访问地址为http://localhost:18000/doc.html#/home

在模块中选择我们的student模块试下方法能否正常访问:点击新增方法的发送:

这样我们的微服务就创建完成了:

  • 8
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 13
    评论
SpringBlade 是一个由商业级项目升级优化而来的SpringCloud分布式微服务架构、SpringBoot单体式微服务架构并存的综合型项目,采用Java8 API重构了业务代码,完全遵循阿里巴巴编码规范。采用Spring Boot 2 、Spring Cloud Hoxton 、Mybatis 等核心技术,同时提供基于React和Vue的两个前端框架用于快速搭建企业级的SaaS多租户微服务平台。 特点: 1、采用前后端分离的模式,前端开源两个框架:Sword (基于 React、Ant Design)、Saber (基于 Vue、Element-UI) 2、后端采用SpringCloud全家桶,并同时对其基础组件做了高度的封装,单独开源出一个框架:BladeTool 3、BladeTool已推送至Maven中央库,直接引入即可,减少了工程的臃肿,也可更注重于业务开发 4、集成Sentinel从流量控制、熔断降级、系统负载等多个维度保护服务的稳定性。 5、注册中心、配置中心选型Nacos,为工程瘦身的同时加强各模块之间的联动。 6、使用Traefik进行反向代理,监听后台变化自动化应用新的配置文件。 7、极简封装了多租户底层,用更少的代码换来拓展性更强的SaaS多租户系统。 8、借鉴OAuth2,实现了多终端认证系统,可控制子系统的token权限互相隔离。 9、借鉴Security,封装了Secure模块,采用JWT做Token认证,可拓展集成Redis等细颗粒度控制方案。 10、稳定生产了两年,经历了从Camden -> Hoxton的技术架构,也经历了从fat jar -> docker -> k8s + jenkins的部署架构 11、项目分包明确,规范微服务的开发模式,使包与包之间的分工清晰。   SpringBlade 更新日志: v3.0.3 新增blade-develop的dockerfile 新增blade-develop推送docker配置 新增saber的dockerfile 新增kuboard k8s部署脚本 新增kuboard k8s部署方案 优化pom配置适配新版部署方案 优化swagger加载逻辑默认开启knife4j
SpringBlade是一个基于Spring+SpringMVC+Beetl+Beetlsql+Shiro的开发框架,它具有权限管理、多角色、父子角色、权限代理等功能,可以实现精确到按钮级别的权限控制。该框架采用前后端分离的模式,前端使用了两个开源框架:Sword(基于React、Ant Design)和Saber(基于Vue、Element-UI),后端采用了SpringCloud全家桶,并对其基础组件进行了高度封装。此外,SpringBlade还集成了Sentinel用于流量控制、熔断降级和系统负载保护,使用Nacos作为注册中心和配置中心,使用Traefik进行反向代理。它还提供了多租户系统、多终端认证系统和细颗粒度控制方案等功能。SpringBlade已经稳定生产了三年,经历了多次技术架构的升级和部署架构的改进。它的项目结构清晰,规范了微服务的开发模式,使各个包之间的分工明确。\[2\]\[3\] #### 引用[.reference_title] - *1* *2* [JavaWeb快速开发框架——Spring Blade集成框架(快速上手)!](https://blog.csdn.net/MaNongXf/article/details/83653196)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [【开源项目】SpringBlade微服务开发平台](https://blog.csdn.net/Roker_966/article/details/124557503)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

灰灰的996

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值