Alisher
Alisher

Reputation: 940

Externalizing spring boot/security configuration

I have multiple microservices that rely on the exact same classes and configuration beans.

Is it possible to externalize this configuration to be included as e.g. module or dependency?

So that e.g. if I would want to change the configuration of these classes all other microservices will have this change.

Upvotes: 0

Views: 438

Answers (2)

Delfino Gomes
Delfino Gomes

Reputation: 385

I think you could clarify your question. If you want properties outside the jar, this is possible following what is described here https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/html/boot-features-external-config.html#boot-features-external-config-application-property-files

If you want to reuse a set of classes, you can create a separate maven module and add it as a dependency in your microservices.

Update #1 (Describing how to create maven module):

  1. Create the module using this site: https://start.spring.io/
  2. Move the reusable code to this new module
  3. Run mvn clean install
  4. Add the module as a dependency in your microservices

Upvotes: 1

Dragos Ionut
Dragos Ionut

Reputation: 257

You can create a library in the "spring-boot-starter" style. Here is how you do it: https://docs.spring.io/spring-boot/docs/2.0.0.M3/reference/html/boot-features-developing-auto-configuration.html

Very short: You will have a spring.factories file where you specify the beans which will be autoconfigured. I recommend you to create conditional beans in library so you will be able to create your own beans in the project, in case you need something else.

Upvotes: 1

Related Questions