I'm building a spring boot application which should support multiple clients. Currently, I've common logic defined at the parent project and customizations at child project. In some cases, the clients may ask additional features or may need extra customization of existing feature which is defined in this child using @Primary
annotation.
The idea here is to keep core logic and customizations separate.
Currently, We are creating different branches for different clients in the child project and customizations are carried out in those which is not the best solution. As no of clients increase no of branches will also increase.
I want a single code where I'll be defining all the customization for all the clients and feature available to each client should be controllable.
I know that this can be achieved by using profiles. But still, even in that case, I've to define profiles for all the component annotations which are cumbersome.
So recently I came up with an idea of using @Componentscan
with a property to control the client logic with the following directory structure.
Parent:
.
└── src
└── main
└── java
├── com.test.parent.controller
├── com.test.parent.dao
└── com.test.parent.service
Child:
.
└── src
└── main
└── java
├── com.test.child.client1.controller
├── com.test.child.client1.dao
├── com.test.child.client1.service
├── com.test.child.client2.controller
├── com.test.child.client2.dao
├── com.test.child.client2.service
├── com.test.child.client3.controller
├── com.test.child.client3.dao
└── com.test.child.client3.service
Mainclass.java
package com.test.child;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan(basePackages = { "com.test.parent.*","com.test.child.${clientname:default}.*" })
public class MainClass {
public static void main(String[] args) {
SpringApplication.run(MainClass.class, args);
}
}
But even, In this case, I'm controlling clients customization by using property clientname
and there is a risk of exposing other client's customization by, passing other client's name.
- Is it possible to control packages or
business logic to be included or excluded during
mvn package
ormvn install
itself provided that the code remains single? i.e isolate logic during build time itself instead of run time. - Seems
maven-compiler-plugin
plugin provides such feature by specifyingincludes
along withpattern
. But how to do the same inspring-boot-maven-plugin
such that the build is controlled by passing property duringmvn package
ormvn install
?
So basically I'm looking something like a filter which supports pattern to include/exclude package/code during mvn build lifecycle.
Not sure <resources><resource>..<\resources><\resource>
can be used to filter code apart from resources.