【LuBase低代码开发框架】二次开发入门:Hello Lubase

基础环境准备

JDK

11

SpringBoot

2.3.7.RELEASE

Maven

二次开发的扩展包可以以正常的springboot项目进行启动,也可以放在lubase的extend目录,通过lubase-core 动态加载扩展包,详情见以下介绍。
一、快速开始
  1. 新建SpringBoot项目,版本2.3.7.RELEASE,设置JDK为11

  
  
  1. <properties >
  2. <java.version > 11 < /java.version >
  3. <project.build.sourceEncoding >UTF- 8 < /project.build.sourceEncoding >
  4. <project. reporting.outputEncoding >UTF- 8 < /project. reporting.outputEncoding >
  5. <spring-boot.version > 2.3.7. RELEASE < /spring-boot.version >
  6. < /properties >
  1. 添加maven依赖:lubase-core 需提前编译。建议 除 lubase-core 之外其他jar不指定版本,采用dependencyManagement中的版本声明

  
  
  1. <dependencies >
  2. <dependency >
  3. <groupId >com.lubase < /groupId >
  4. <artifactId >lubase-core < /artifactId >
  5. <version > 0.9.0 < /version >
  6. < /dependency >
  7. <dependency >
  8. <groupId >org.springframework.boot < /groupId >
  9. <artifactId >spring-boot-starter-cache < /artifactId >
  10. < /dependency >
  11. <dependency >
  12. <groupId >org.springframework.boot < /groupId >
  13. <artifactId >spring-boot-starter < /artifactId >
  14. < /dependency >
  15. <dependency >
  16. <groupId >org.springframework.boot < /groupId >
  17. <artifactId >spring-boot-starter-test < /artifactId >
  18. <scope > test < /scope >
  19. <exclusions >
  20. <exclusion >
  21. <groupId >org.junit.vintage < /groupId >
  22. <artifactId >junit-vintage-engine < /artifactId >
  23. < /exclusion >
  24. < /exclusions >
  25. < /dependency >
  26. < /dependencies >
  1. 调整dependencyManagement,指定版本

  
  
  1. <dependencyManagement >
  2. <dependencies >
  3. <dependency >
  4. <groupId >org.springframework.boot < /groupId >
  5. <artifactId >spring-boot-dependencies < /artifactId >
  6. <version >${spring-boot.version} < /version >
  7. < type >pom < / type >
  8. <scope >import < /scope >
  9. < /dependency >
  10. < /dependencies >
  11. < /dependencyManagement >
  1. 在项目添加application.yml,可从lubase项目进行复制
  2. 修改启动类,添加如下标记 @EnableCaching 和

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class }, scanBasePackages = "com.lubase.*")

  1. 修改打包配置,建议去除相配置文件,然后打包为瘦jar包

  
  
  1. <build >
  2. <plugins >
  3. <plugin >
  4. <groupId >org.apache.maven.plugins < /groupId >
  5. <artifactId >maven-compiler-plugin < /artifactId >
  6. <version > 3.8.1 < /version >
  7. < configuration >
  8. < source > 11 < / source >
  9. <target > 11 < /target >
  10. <encoding >UTF- 8 < /encoding >
  11. < / configuration >
  12. < /plugin >
  13. <plugin >
  14. <groupId >org.apache.maven.plugins < /groupId >
  15. <artifactId >maven-surefire-plugin < /artifactId >
  16. <version > 3.0.0-M 7 < /version >
  17. < configuration >
  18. <skipTests > true < /skipTests >
  19. < / configuration >
  20. < /plugin >
  21. <plugin >
  22. <groupId >org.apache.maven.plugins < /groupId >
  23. <artifactId >maven-jar-plugin < /artifactId >
  24. <version > 3.2.2 < /version >
  25. < configuration >
  26. <excludes >
  27. <exclude > *.yml < /exclude >
  28. <exclude > *.yaml < /exclude >
  29. <exclude >templates / < /exclude >
  30. < /excludes >
  31. <archive >
  32. <manifest >
  33. <mainClass >com.lubase.extenddemo.ExtendDemoApplication < /mainClass >
  34. <addClasspath > true < /addClasspath >
  35. <classpathPrefix >lib / < /classpathPrefix >
  36. < /manifest >
  37. < /archive >
  38. < / configuration >
  39. < /plugin >
  40. <plugin >
  41. <groupId >org.apache.maven.plugins < /groupId >
  42. <artifactId >maven-dependency-plugin < /artifactId >
  43. <version > 2.8 < /version >
  44. <executions >
  45. <execution >
  46. <id > copy < /id >
  47. <phase >package < /phase >
  48. <goals >
  49. <goal >copy-dependencies < /goal >
  50. < /goals >
  51. < configuration >
  52. <outputDirectory >
  53. ${project.build.directory} /lib
  54. < /outputDirectory >
  55. < / configuration >
  56. < /execution >
  57. < /executions >
  58. < /plugin >
  59. < /plugins >
  60. < /build >
  1. 编写hello lubase

lubase 提供了很多个可供扩展的接口,用于不同的场景,详细见:lubase后端扩展接口

以下代码提供了一个最基本扩展方法


  
  
  1. package com. lubase. extenddemo;
  2. import com. lubase. core. extend. IInvokeMethod;
  3. import org. springframework. stereotype. Component;
  4. import java. util. HashMap;
  5. @Component
  6. public class HelloFromExtend implements IInvokeMethod {
  7. @Override
  8. public boolean checkRight( ) {
  9. return false;
  10. }
  11. @Override
  12. public Object exe( HashMap< String, String> hashMap) throws Exception {
  13. return "hello lubase";
  14. }
  15. @Override
  16. public String getDescription( ) {
  17. return "测试扩展方法:hello lubase";
  18. }
  19. @Override
  20. public String getId( ) {
  21. // 设置唯一的方法id
  22. return "1181294501122019328";
  23. }
  24. }
  1. 打包后启动程序即可进行验证

java -jar extend-demo.jar


  
  
  1. POST / invoke / method HTTP / 1.1
  2. Token: eyJ 0eXAiOiJKV 1QiLCJhbGciOiJIUzI 1NiJ 9.eyJ 1Y 28iOiJhZG 1pbjEiLCJhdWQiOiI 2ODgxNjQwNzA 2ODcyNDgzODQiLCJ 1bmEiOiJhZG 1pbjEiLCJ 1b 3IiOiIxIiwiZXhwIjoxNzE 4NjU 1MjgzfQ.ZBWf 7xDjouugGe 9FCo 40Riw 6hKbEetFFJSvB 4DvkKF 8
  3. User-Agent: Apipost / 8 (https: / /www.apipost.cn)
  4. Content-Type: application /json
  5. Host: localhost: 8084
  6. Content-Length: 116
  7. {
  8. "pageId": "697491263502422016",
  9. "appId": "671085014334574592",
  10. "methodId": "1181294501122019328",
  11. "data": {}
  12. }

  
  
  1. {
  2. "success": 1,
  3. "code": "1000",
  4. "message": "处理成功",
  5. "data": "hello lubase",
  6. "timestamp": "1718629442660"
  7. }
二、动态加载扩展包

场景:通常有这样一种情况,有多个应用都进行了二次开发,但是二开内容不多,同时不希望为每个应用部署一个后端服务,可以通过启动一个lubase-core 服务,动态加载这些应用的扩展jar包即可。

在yaml 文件中 custom.extend-path 属性指定了扩展目录,在启动lubase-core时(或者引用了lubase-core)会扫描扩展目录的jar并进行加载,参考如下: java -jar lubase-core.jar

完整的demo 详见:extend-demo: 这次后端二次开发的一个demo

 LuBase低代码系列文章:

【开发工具自荐】LuBase 低代码开发框架介绍-可私有化部署-CSDN博客

【LuBase低代码框架】表单引擎字段类型设计-CSDN博客

【LuBase低代码框架】私有化部署后如何扩展文件存储?-CSDN博客

【LuBase低代码框架】5分钟快速构建一个应用?-CSDN博客

入群交流:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值