Spring boot application.properties maven multi-module projects

hibernate, maven, spring, spring-boot

Solution

Maybe you should only use `application.properties` in the top-level aggregator project?

You can always use `@PropertySource` in the child projects to configure them with a name that is specific to their use case.

Or you can use different names for each project and glue them together in the top-level project using `spring.config.location` (comma-separated).

Problem

We are using spring boot in a multi-module project. We have a Domain access module which has the common domain object classes, repositories, together with configuration for the datasource, JPA, Hibernate, etc. These are configured using a application.properties. We put all this configuration into the common module to save duplicating these common configurations in the higher level modules. This all works fine when building the domain module, so the configurations are loaded correctly in the test units. However the problems start when we try to use the domain module in the higher layer modules; they have their own application.properties which means Spring loads them and not the the Domain module application.properties, which this means the data source is not configured because only the higher module application.properties are loaded. What we would like is both the domain module and higher level application properties to be loaded by Spring. But we can't see any easy way to do this. I'm thinking this must be a common problem, and wonder if there any recommended solutions for this problem? As we are using spring-boot the solution should ideally use annotations instead of applictionContext.xml.

Original source