FlexiCore Boot Hello World

A refresher on FlexiCore Boot (version 5.0)

With FlexiCore Boot you can add FlexiCore capabilities to an existing Spring Boot application.
With FlexiCore Boot you can add different features of FlexiCore when you need them, for example:
  • Start with plugins support only , use FlexiCore unique ability to use inter-dependent plugins.
  • Add plugins’ REST API support, your plugins can now add REST endpoints to your application and other plugins existing ones.
  • Define domain model entities in plugins. Extend your domain model using plugins. Or define the entire domain model through plugins.
  • Add multi-tenancy access control support to an existing Spring Boot application domain model.
  • Add additional capabilities using existing plugins from the FlexiCore marketplace.
  • Note: the latest guide with code for FlexiCore boot demo is available on GitHub
    • It starts with a Spring Boot application having no FlexiCore dependencies
    • In stages, based on branches, additional steps are taken in developing plugins for the first version of the application  

What you’ll need

Development requirements

A Java™ Development Kit (JDK) installed. We recommend AdoptOpenJDK version 11 or 8.

Apache Maven version 3.1 or later installed.

Optional

An Integrated Developer Environment (IDE)

Popular choices include IntelliJ IDEA, Spring Tools, Visual Studio Code, or Eclipse, and many others.

Testing and running requirements

Java installed (version 8 or better)

What you'll build

You will build a Spring Boot Application and expand it with two interdependent plugins.

Step 1: Create a minimal Spring Boot Application

Project Structure

Step 2: Update POM.XML

Step 3: Update the application code

The created application is a standard Spring Boot application.

You can skip the previous part if you want to add plugins support to an existing Spring Boot application.

Step 4: Build and run the Spring Boot application

You can now create the Spring Boot application by running:

mvn package 

from the command line when your current folder is where the pom.xml resides.

Alternatively, you can package from the IDE.

from the command line, change the current directory to the target folder and run

 

 

the above is a standard hello world Spring Boot application.

We will now add FlexiCore plugins support using a single annotation.

Step 5: Add FlexiCore-boot plugins support.

Add the required FlexiCore Boot Dependency in your pom.xml
 
Add the required annotation to your application code

The only annotation required for supporting inter-dependent plugins is:
@EnableFlexiCorePlugins

 

You will need to re-compile the Spring Boot application after including the required dependency on FlexiCore Boot and the required annotation.

Once the application is compiled with the above annotation, additional features can be added using 

Step 5.1 : Create a simple hello-world plug-in

 

We will build a simple plugin that will do nothing but adding some information to our log file.

Create a new Maven-based project.

Change the pom.xml file to the content below.

Update the HelloWorld class file. 

build the plugin by 

mvn package

copy the created jar file into the plugins folder under the folder where the main spring application is located.

Before we run our application we need to make sure that the application.properties file inside the config folder is properly defined.

Step 5.2: set Spring application.properties file

In case you are adding plugins support to an existing application with an existing application.properties file, add one line to your properties file

flexicore.plugins=plugins

Save the file in the config folder and name it :

application.properties

 

Step 5.3: set Spring logback-spring.xml file

Save the file in the config folder name it :

logback-spring.xml

Note: The structure of both files allows moving this file structure to any location,.

Now run the Spring boot  application:
Form the command line:

You can verify that the plugin was correctly run and deployed by looking into the log folder 
You should see a line similar to this:

Step 6: Create an injected (auto-wired) plugin

Note: FlexiCore plugin system for Spring is unique as it allows plugins to provide services to other plugins, this is possible to any depth.

When building a dependent plugin, the injected plugin maven coordinates are needed in the pom.xml file. The injection is done in runtime by FlexiCore, thus the scope entry in the pom.xml is set to ‘provided’. So, the created dependent plugin jar doesn’t include any of the classes defined in the injected plugin.

Create a new Maven project and replace the pom file:

 

Step 6.1: Update the main class file

Step 6.2: build the injected plugin

./mvn install

or install from the IDE

copy the provider-1.0.0.jar file into the plugins folder hosting the previous plugin.

if you now run the application you will find that there are two plugins detected:

Step 6.3: update and build the HelloWorld plugin

We will now show how the HelloWorld plugin makes use of the new provider plugin.

Add the maven coordinates of the injected plugins to pom.xml and update few other sections:

Note: The last section is essential, plugins using injected plugins should declare the plugin-dependencies section as a comma-separated list of plugins artifact-id and version. This should be placed inside the manifestEntries section of the maven shade-plugin section of the full pom.xml of the HelloWorld plugin above.

Step 6.3.1: update the HelloWorld class

Note the added lines

Now the provider plugin bean is injected to the HelloWorld plugin and its public methods, entities and classes are available from within the HelloWorld plugin.

Obviously, the injected plugin has no ‘knowledge’ of other plugins using its services.

Build the HelloWorld plugin and copy it into the plugins folder.
now run the Spring Boot application again:

Verify by looking at the log file: