0

First of all, I am new to Spring Boot so I am not sure if something like this is possible within the framework.

Let me describe my problem.

I have 10 code repositories. Each repository listens to a data stream, parses the data and updates a database. Due to maintainability issues I plan on bringing it under a single code repository. This new application will be generalized, and certain app specific configurations (for example, which stream should I connect to, the database host) will be retrieved at run-time.

Theoretically, this would allow me to maintain a single code base, but deploy it as 10 separate services based on configurations which is what I need. However, there's a set of java classes that are application specific used to parse the retrieved data. To better understand this refer the diagram below.

enter image description here

Ideally, I need to still maintain these classes in the same repository, but as separate modules. Once the configurations are loaded, the app should be able to load the corresponding module into the application context and initialize the Java classes. The other modules will not be used.

Can I do something like this with Spring Boot? Alternately, even a build time solution is fine if I can create separate builds which can then be deployed separately.

Priyath Gregory
  • 927
  • 1
  • 11
  • 37
  • From what I understand in your explanation, there will be different configuration setting, and also there is a condition that load separate module base on the configuration setting. It should be capable to done with spring boot. By "runtime config load", it means load config at first time/start, not load config when it is change. – Erwin Sep 16 '20 at 06:05
  • Yes correct. When the app is initialized, corresponding configs will be loaded. Based on that, conditionally the module will be added to the application context – Priyath Gregory Sep 16 '20 at 06:24
  • then it should be no problem. just create different configs and if condition inside the loader base on the config – Erwin Sep 16 '20 at 06:27
  • I can it using if conditions I guess, but I was wondering if there was a "Spring" approach to handle this problem. – Priyath Gregory Sep 16 '20 at 06:31
  • maybe you can try [this](https://docs.spring.io/spring-boot/docs/1.1.4.RELEASE/reference/html/boot-features-developing-auto-configuration.html) or [this](https://stackoverflow.com/questions/40805258/how-to-make-a-configuration-conditional-on-another-configuration) – Erwin Sep 16 '20 at 06:35

1 Answers1

1

Not sure did I understood it well but why don't try spring profile (https://www.baeldung.com/spring-profiles). You can set for every service different config and with spring.profiles.active in runtime say what configuration will use.

Also something like this could be useful https://www.baeldung.com/spring-reloading-properties

SinisaT90
  • 92
  • 2
  • Hey thanks for the answer. I skimmed through it on the surface and will go through it in depth at a later point. But it looks like loading properties or configs based on something like an environment variable right? My requirement is to load modules based on an injected property. By modules, its just a bunch of java classes that I want to initialze – Priyath Gregory Sep 17 '20 at 10:09
  • 1
    Yeah you can use environment variable or pass argument on runtime, depends how you do deployment. But if you have modules you should do custom maven/gradle build script for every module in combination with spring profile. With custom build scripts you can define what packages/classes you use. – SinisaT90 Sep 17 '20 at 10:51
  • Do you have any documentation that I could refer to implement something like that? – Priyath Gregory Sep 17 '20 at 13:17
  • 1
    You can check this https://guides.gradle.org/creating-multi-project-builds/ and maybe this https://stackoverflow.com/questions/12102388/custom-pom-xml-filename-in-maven-multimodule – SinisaT90 Sep 17 '20 at 13:27