hank-cp / sbp

Plugin framework for Spring Boot based on pf4j.
Apache License 2.0
202 stars 66 forks source link
pf4j plugin plugins sbp sping spring-boot

GitHub release Maven Central Test GitHub GitHub last commit

sbp introduce plugin oriented programming to Spring Boot. It is inspired and builds on top of Pf4j project.

❗️❗️❗️sbp supports Spring Boot 3.x ONLY from version 18. If you are still using Spring Boot 2.x, please stay with the old version of sbp.

中文

Why we need plugin for Spring Boot?

Feature / Benefits

vs OSGi Based Server (Eclipse Virgo \ Apache Karaf)
vs Spring Cloud

Getting Started

Create app project
  1. Create a Spring Boot project with multi sub project structure.
    1. For Gradle, it means multiple projects
    2. For Maven, it means multiple modules
    3. Take the demo projects for reference.
  2. Introduce sbp-spring-boot-starter to dependencies.
    • Maven
      <dependency>
          <groupId>org.laxture</groupId>
          <artifactId>sbp-spring-boot-starter</artifactId>
          <version>3.3.25</version>
      </dependency>
    • Gradle
      dependencies {
          implementation "org.springframework.boot:spring-boot-starter-web"
          implementation "org.springframework.boot:spring-boot-starter-aop"
          implementation 'org.laxture:sbp-spring-boot-starter:3.3.25'
      }
    • Latest master code is always available with version -SNAPSHOT
  3. Add belows to application.properties.
    spring.sbp.runtimeMode = development
    spring.sbp.enabled = true
    # remember to add this line in case you are using IDEA
    spring.sbp.classes-directories = "out/production/classes, out/production/resources"
  4. Add anything you want in this project like Controller, Service, Repository, Model, etc.
  5. Create an empty folder named plugins.
Create plugin project
  1. Create a plain Spring Boot project in the plugins folder.
  2. Add plugin.properties file to the plugin project.
    plugin.id=<>
    plugin.class=demo.sbp.admin.DemoPlugin
    plugin.version=0.0.1
    plugin.provider=Your Name
    plugin.dependencies=
  3. Introduce sbp-core to dependencies.
    • Maven
      <dependency>
          <groupId>org.laxture</groupId>
          <artifactId>sbp-core</artifactId>
          <version>3.3.25</version>
      </dependency>
    • Gradle
      dependencies {
          implementation 'org.laxture:sbp-core:3.3.25'
      }
  4. Add Plugin class

    public class DemoPlugin extends SpringBootPlugin {
    
        public DemoPlugin(PluginWrapper wrapper) {
            super(wrapper);
        }
    
        @Override
        protected SpringBootstrap createSpringBootstrap() {
            return new SpringBootstrap(this, AdminPluginStarter.class);
        }
    }
  5. Add anything you want in the plugin project like Controller, Service, Repository, Model, etc.

Everything is done and now you could start the app project to test the plugin.

Documentation

License

/*
 * Copyright (C) 2019-present the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */