Skip to content

Configuration per module for Spring Boot projects

License

Notifications You must be signed in to change notification settings

tleipzig/springify-multiconfig

Repository files navigation

Springify Multiconfig Build Status Maven Central Licence

Springify Multiconfig loads application YAML files from all jars in the classpath into the application context of a Spring Boot application, helping to split the configuration of multi-module projects.

It’s part of Springify, a set of open source libraries supporting the development of Spring Boot projects.

Usage

Just add the dependency from the Maven Central Repository:

<dependency>
  <groupId>com.it-surmann</groupId>
  <artifactId>springify-multiconfig</artifactId>
  <version>1.0.0</version>
</dependency>

Springify Multiconfig is now scanning for files with the name application-mc-*.yml, which are then loaded into the application context.

Example

A typical multi-module project may look like this.

 +-------------------+
 |    module-web     | containing application.yml, application-prod.yml
 +-------------------+
          |
          V
 +-------------------+
 |    module-blog    | containing application-mc-blog.yml
 +-------------------+
          |
          V
 +-------------------+
 | module-newsletter |  containing application-mc-newsletter.yml
 +-------------------+
          |
          V
 +-------------------+
 |   module-basics   | containing application-mc-basics.yml
 +-------------------+

The separation helps to keep code and configuration together, so each module can provide its own configuration if needed. The default behaviour for initializing the application context remains untouched, so in the example the application YAML files of module-web are loaded by Spring Boot itself (depending on the active profile).

Tip
Specify the dependency to springify-multiconfig on the lowest module (module-basics).

When the application is started, all modules are part of it and all application YAML files are loaded. They are ordered corresponding to the dependency graph, so in the example the application-mc-blog.yml would override properties of application-mc-newsletter.yml and application-mc-basics.yml with the same name (if present).

If a module contains a test class initializing the context, only the application YAML files of the current module plus dependencies are loaded. For example a class NewsletterServiceIT in module-newsletter annotated with @SpringBootTest would load application-mc-basics.yml as well as application-mc-newsletter.yml, but nothing else.

About

Configuration per module for Spring Boot projects

Resources

License

Stars

Watchers

Forks

Packages

No packages published