芋道源码微服务新建新的模块及代码生成器使用

2024-09-03 14:20

本文主要是介绍芋道源码微服务新建新的模块及代码生成器使用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录

  • 概述
  • 实践
    • 新建模块
    • 代码生成
      • 配置数据源
      • 代码生成
      • 拷贝代码
        • pom.xml
      • 其它的
    • 问题
      • redis
      • 权限配置
    • 效果
  • 结束

概述

  芋道源码微服务新建新的模块及代码生成器使用。主要分三块,建立新的模块,代码生成及运行过程中的问题解决。

实践

新建模块

  参考芋道源码本身的架构,新建的工程架构如下图所示,代码生成器也会生成对应的架构,但没有pom.xml这些配置文件,需要自己添加。
在这里插入图片描述

代码生成

  官方的代码生成器已经很强大,生产环境下,需要根据自己公司业务需求,做对应需求的调整。

配置数据源

  先配置数据源,芋道源码会报演示模式,无法进行写操作! ,我是直接调试代码,找到对应的代码,将其注释了,与公司业务无关的,最好慢慢清理掉,使整个框架更简洁。
在这里插入图片描述

代码生成

  先导入,再编辑,最后预览一下生成的代码。这一步,还是简单的。
在这里插入图片描述

拷贝代码

  将代码直接拷贝至对应工程,看着无错,但运行时是有问题的。

pom.xml

api工程

<dependencies><dependency><groupId>com.fun</groupId><artifactId>funcloud-common</artifactId></dependency><!-- Web 相关 --><dependency><groupId>org.springdoc</groupId><artifactId>springdoc-openapi-ui</artifactId><scope>provided</scope> <!-- 设置为 provided,主要是 PageParam 使用到 --></dependency><!-- 参数校验 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-validation</artifactId><optional>true</optional></dependency><!-- RPC 远程调用相关 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId><optional>true</optional></dependency></dependencies>

biz 工程

<dependencies><!-- Spring Cloud 基础 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-bootstrap</artifactId></dependency><dependency><groupId>com.fun</groupId><artifactId>funcloud-spring-boot-starter-env</artifactId></dependency><!-- 依赖服务 --><dependency><groupId>com.fun</groupId><artifactId>funcloud-module-system-api</artifactId><version>${revision}</version></dependency><dependency><groupId>com.fun</groupId><artifactId>funcloud-module-extract-api</artifactId><version>1.0-SNAPSHOT</version></dependency><!-- 业务组件 --><dependency><groupId>com.fun</groupId><artifactId>funcloud-spring-boot-starter-biz-data-permission</artifactId></dependency><!-- Web 相关 --><dependency><groupId>com.fun</groupId><artifactId>funcloud-spring-boot-starter-security</artifactId></dependency><!-- DB 相关 --><dependency><groupId>com.fun</groupId><artifactId>funcloud-spring-boot-starter-mybatis</artifactId></dependency><!-- RPC 远程调用相关 --><dependency><groupId>com.fun</groupId><artifactId>funcloud-spring-boot-starter-rpc</artifactId></dependency><!-- Registry 注册中心相关 --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId></dependency><!-- Config 配置中心相关 --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId></dependency><!-- Test 测试相关 --><dependency><groupId>com.fun</groupId><artifactId>funcloud-spring-boot-starter-test</artifactId><scope>test</scope></dependency><!-- 工具类相关 --><dependency><groupId>com.fun</groupId><artifactId>funcloud-spring-boot-starter-excel</artifactId></dependency><!-- 监控相关 --><dependency><groupId>com.fun</groupId><artifactId>funcloud-spring-boot-starter-monitor</artifactId></dependency>
</dependencies>

其它的

  父工程需要引入 芋道源码 依赖管理,ErrorCodeConstants 类需要手动修改。

问题

   1.缺少 redis 配置,两种解决方式,一种是提供对应的redis配置,即可解决,另一种,不加载对应的AutoConfig 配置类;2.缺少对应的权限配置类。

redis

在这里插入图片描述

权限配置

  权限配置,调试及优化后如下

@Configuration(proxyBeanMethods = false, value = "extractSecurityConfiguration")
public class SecurityConfiguration {@Value("${spring.boot.admin.context-path:''}")private String adminSeverContextPath;@Bean("extractAuthorizeRequestsCustomizer")public AuthorizeRequestsCustomizer authorizeRequestsCustomizer() {return new AuthorizeRequestsCustomizer() {@Overridepublic void customize(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry) {// Swagger 接口文档registry.antMatchers("/v3/api-docs/**").permitAll() // 元数据.antMatchers("/swagger-ui.html").permitAll(); // Swagger UI// Spring Boot Actuator 的安全配置registry.antMatchers("/actuator").anonymous().antMatchers("/actuator/**").anonymous();// Druid 监控registry.antMatchers("/druid/**").anonymous();// Spring Boot Admin Server 的安全配置registry.antMatchers(adminSeverContextPath).anonymous().antMatchers(adminSeverContextPath + "/**").anonymous();
//                // 文件读取
//                registry.antMatchers(buildAdminApi("/infra/file/*/get/**")).permitAll();// TODO 芋艿:这个每个项目都需要重复配置,得捉摸有没通用的方案// RPC 服务的安全配置registry.antMatchers(ApiConstants.PREFIX + "/**").permitAll();}};}}

效果

在这里插入图片描述

结束

  经过上述步骤后,新建的模块即可运行。

这篇关于芋道源码微服务新建新的模块及代码生成器使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1133203

相关文章

使用Python实现矢量路径的压缩、解压与可视化

《使用Python实现矢量路径的压缩、解压与可视化》在图形设计和Web开发中,矢量路径数据的高效存储与传输至关重要,本文将通过一个Python示例,展示如何将复杂的矢量路径命令序列压缩为JSON格式,... 目录引言核心功能概述1. 路径命令解析2. 路径数据压缩3. 路径数据解压4. 可视化代码实现详解1

Pandas透视表(Pivot Table)的具体使用

《Pandas透视表(PivotTable)的具体使用》透视表用于在数据分析和处理过程中进行数据重塑和汇总,本文就来介绍一下Pandas透视表(PivotTable)的具体使用,感兴趣的可以了解一下... 目录前言什么是透视表?使用步骤1. 引入必要的库2. 读取数据3. 创建透视表4. 查看透视表总结前言

Python 交互式可视化的利器Bokeh的使用

《Python交互式可视化的利器Bokeh的使用》Bokeh是一个专注于Web端交互式数据可视化的Python库,本文主要介绍了Python交互式可视化的利器Bokeh的使用,具有一定的参考价值,感... 目录1. Bokeh 简介1.1 为什么选择 Bokeh1.2 安装与环境配置2. Bokeh 基础2

Android使用ImageView.ScaleType实现图片的缩放与裁剪功能

《Android使用ImageView.ScaleType实现图片的缩放与裁剪功能》ImageView是最常用的控件之一,它用于展示各种类型的图片,为了能够根据需求调整图片的显示效果,Android提... 目录什么是 ImageView.ScaleType?FIT_XYFIT_STARTFIT_CENTE

Java学习手册之Filter和Listener使用方法

《Java学习手册之Filter和Listener使用方法》:本文主要介绍Java学习手册之Filter和Listener使用方法的相关资料,Filter是一种拦截器,可以在请求到达Servl... 目录一、Filter(过滤器)1. Filter 的工作原理2. Filter 的配置与使用二、Listen

Pandas使用AdaBoost进行分类的实现

《Pandas使用AdaBoost进行分类的实现》Pandas和AdaBoost分类算法,可以高效地进行数据预处理和分类任务,本文主要介绍了Pandas使用AdaBoost进行分类的实现,具有一定的参... 目录什么是 AdaBoost?使用 AdaBoost 的步骤安装必要的库步骤一:数据准备步骤二:模型

使用Pandas进行均值填充的实现

《使用Pandas进行均值填充的实现》缺失数据(NaN值)是一个常见的问题,我们可以通过多种方法来处理缺失数据,其中一种常用的方法是均值填充,本文主要介绍了使用Pandas进行均值填充的实现,感兴趣的... 目录什么是均值填充?为什么选择均值填充?均值填充的步骤实际代码示例总结在数据分析和处理过程中,缺失数

如何使用 Python 读取 Excel 数据

《如何使用Python读取Excel数据》:本文主要介绍使用Python读取Excel数据的详细教程,通过pandas和openpyxl,你可以轻松读取Excel文件,并进行各种数据处理操... 目录使用 python 读取 Excel 数据的详细教程1. 安装必要的依赖2. 读取 Excel 文件3. 读

Python的time模块一些常用功能(各种与时间相关的函数)

《Python的time模块一些常用功能(各种与时间相关的函数)》Python的time模块提供了各种与时间相关的函数,包括获取当前时间、处理时间间隔、执行时间测量等,:本文主要介绍Python的... 目录1. 获取当前时间2. 时间格式化3. 延时执行4. 时间戳运算5. 计算代码执行时间6. 转换为指

SpringBoot基于配置实现短信服务策略的动态切换

《SpringBoot基于配置实现短信服务策略的动态切换》这篇文章主要为大家详细介绍了SpringBoot在接入多个短信服务商(如阿里云、腾讯云、华为云)后,如何根据配置或环境切换使用不同的服务商,需... 目录目标功能示例配置(application.yml)配置类绑定短信发送策略接口示例:阿里云 & 腾