Reputation: 395
I am creating a project with spring-boot
.
Spring boot maven structure mandates that it has a parent defined to spring-boot-starter-parent
.
I have a situation where I would like to package my application as a multi-module structure where I define modules which contain functionality related to a geography.
Something like this, each module has a jar packaging,
parent Pom
|
|-----------Core module
|
|-----------India Module
|
|----------Africa Module
|
|--------- Europe Module
Now, I can package my application depending on geography using maven profiles where in India profile only core module and India module are included and packaged.
How can I achieve it using spring boot where my parent is already defined to spring-boot-starter-parent
?
Upvotes: 5
Views: 12305
Reputation: 3059
Right now you can solve that problem using official Spring guidline and create Spring Boot Multi-Module project. Just follow the instruction https://spring.io/guides/gs/multi-module/
Upvotes: 1
Reputation: 395
There are two ways one can do it,
use dependencyManagement in your parent pom as in
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<type>pom</type>
<version>1.2.3.RELEASE</version>
<scope>import</scope>
</dependency>
</dependencies>
This is the way I am doing it. The root POM (with pom packaging) has spring boot as parent
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.3.RELEASE</version>
</parent>
the module poms have root pom as parent. The core module POM adds has dependency on other modules. It also has 'spring-boot-maven-plugin' to create the fat jar.
The spring context is started with java -jar Core_xxx.release.jar
Off course if you have organization wise parent POM then first option would be more appropriate.
Upvotes: 12
Reputation: 807
I don't know specifically about Spring Boot.
But in general using Spring this can be done by common configuration packages. So in your main App/Configuration you do a:
@Configuration
@ComponentScan("com.example.common.bootstrap")
And then you can just put module specific config in the bootstrap package for each module. So just create a com.example.common.boostrap.AsiaModule and com.example.common.bootstrap.EuropeModule as Spring Configurations and you are good.
Upvotes: 0