Implementing plugin architecture in Spring Annotation Database Boot application

I want to implement the plugin architecture in a Spring Boot application. Let me explain my scenario. I have a main application that starts the server, manages security, etc. The application is similar to the root of my final product, which will include this root application and other plugins added to it.

Now plugins are a Spring Boot application that I can add to the root application, dynamically search for banks in a specific path or add them depending on the project as a library.

Plugins have their own configurations and are similar to applications running inside the main root application. Say, if the root application starts the server, the plugin application can have all the controllers (endpoints), beans, etc. that provide functionality to my product.

This is a premise, now I want to know

  • How can I achieve this architecture?
  • How will the root application interact with plugins?
  • Will they have separate application contexts?
  • How to download and configure a child application from the root application?
  • When an application receives a request from clients, how can I redirect a request to a specific controller inside a specific plugin, given that I can have many plugins.

I am confused by this concept and how it can work. Any help is appreciated. If there is an example that anyone can provide, it will be just great.

+10
source share
3 answers

This post was 3 years ago. However, I would like to answer this question for those who are looking for a solution for such a scenario. It seems that pf4j, which is a plugin, is suitable for you. Besides supporting native application, it also has spring-pf4j, so you can use it in spring.

URL: https://pf4j.org

+4
source

As described in the Java dyanmically load plugin , you have tow options:

  • Switching to an OSGi method that takes into account all your questions, but can be a bit complicated in combination with Spring boot
  • Using ServiceLoader

At a minimum for the second approach, each jar file must implement the same interface that you can use to register the contents of the jar file (similar to the method for starting the OSGi package). This way you can split the application context for each jar file and only make it available at startup (for example, you could create a context hierarchy into which you add the added jar context to the root context).

Your last point can be tricky as you have to consider that there may be several services that could fulfill the same request. Returning to a sheet from OSGi, these services are usually defined through a common interface, and implementations have a sort of priority, which indicates which service should be used if there are several. Of course, there are other approaches that you can define to choose one or the other.

+5
source

There are two possible options 1. Using spring-plugin, you can use the OSGi function. https://github.com/spring-projects/spring-plugin 2. using mirco-boot, which will use the spring boot end and the mircoserver frontend. it also provides plugin support as per your requirement. You can research https://github.com/aol/micro-server/tree/master/micro-boot

0
source

Source: https://habr.com/ru/post/1232769/


All Articles