在当下后端市场,还是以spring-boot为核心框架进行系统开发,本框架可以在spring-boot系统上进行插件式的开发,将插件当做一个mini版本的spring-boot进行系统扩展开发,可以解决如下痛点:
该框架可以在spring-boot项目上开发出插件功能,在插件中可以和spring-boot使用方式一模一样。使用了本框架您可以实现如下需求:
com.gitee.starblues
spring-brick
${latest.version}
plugin:
runMode: dev
mainPackage: com.gitee.starblues.example
pluginPath:
- D://project//plugins(替换为自己环境下插件目录)
runMode: 运行模式, 开发环境: dev; 生产环境: prod。dev环境下,只适用于在idea环境下开发调试,prod环境只能加载打包的插件,比如jar、zip等,插件打包详见: 插件打包详细说明
mainPackage: 主程序扫描的包名。
pluginPath: 插件目录或者插件上级目录,可配置多个。
import com.gitee.starblues.loader.launcher.SpringMainBootstrap;
import com.gitee.starblues.loader.launcher.SpringBootstrap;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application implements SpringBootstrap {
public static void main(String[] args) {
// 该处使用 SpringMainBootstrap 引导启动
SpringMainBootstrap.launch(Application.class, args);
}
@Override
public void run(String[] args) throws Exception {
// 在该实现方法中, 和 SpringBoot 使用方式一致
SpringApplication.run(Application.class, args);
}
}
org.springframework.boot
spring-boot-starter
${和主程序一致的springboot版本}
com.gitee.starblues
spring-brick-bootstrap
${latest.version}
主程序的 groupId
主程序的 artifactId
主程序 version
provided
注意:插件包名不能和主程序包名一致,如需一致,需遵循:插件包名范围小于等于主程序包名。
详细规则可见:https://www.yuque.com/starblues/spring-brick-3.0.0/siet7b
import com.gitee.starblues.bootstrap.SpringPluginBootstrap;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ExamplePlugin extends SpringPluginBootstrap {
public static void main(String[] args) {
new ExamplePlugin().run(args);
}
}
com.gitee.starblues
spring-brick-maven-packager
${latest.version}
dev
plugin-example
com.gitee.starblues.example.ExamplePlugin
1.0.0-SNAPSHOT
repackage
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/example")
public class ExampleController {
@GetMapping
public String hello(){
return "hello";
}
}
c.g.s.i.operator.DefaultPluginOperator : 插件加载环境: dev
c.g.s.core.PluginLauncherManager : 插件[plugin-example@1.0.0-SNAPSHOT]加载成功
c.g.s.b.p.web.PluginControllerProcessor : 插件[plugin-example]注册接口: {GET [/plugins/module1/example]}
c.g.s.core.PluginLauncherManager : 插件[plugin-example@1.0.0-SNAPSHOT]启动成功
c.g.s.i.operator.DefaultPluginOperator : 插件初始化完成
页面更新:2024-03-31
本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828
© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号