I have a small Spring Boot application which I must adapt to use a custom parent. Google finds lots of examples of how to migrate to Spring Boot, but I am at a loss as to migrate from Spring Boot (which I barely know to begin with).
The reasons
To make things short, this application was developed as a kind of a proof-of-concept and the developer chose state-of-the-art technologies.
Now, this application will keep on living and we need to integrate it in our framework. As a Maven project, it should therefore inherit one of our common parent, though it is my understanding Spring Boot projects should inherit from the Spring Boot starter parent POM.
[Edit] I was incorrect: it is possible to use Spring Boot without the parent POM. Removing Spring Boot is therefore not an obligation, but our parent POM includes its own version management, which obliges me to override several versions included in the starter.
Why we need to inherit from our parent
We have an enterprise framework used across all our projects. To make things easier, we manage versions of many frameworks in our parent POM. Some examples where these versions conflict with the ones from spring-boot-dependencies in our little batch project:
- Spring framework (in-house: 3.2.4; Spring Boot 1.2.2: 4.1.5)
- Spring Batch (ih: 2.2.0; sb: 3.0.3)
- Velocity (ih: 1.5; sb: 1.7)
- Junit (ih: 4.11; sb: 4.12)
- ... (we manage about 90 versions)
I am obviously not at liberty to upgrade those versions. Please keep in mind this framework is used across many projects and any change could have dramatic and uncontrolled consequences.
Additional context
The objective is to get a little Spring batch application. It must take some input from the command line and return a 12
exit code if execution fails. Below is the core of the launcher but I am open to any better way to do it.
Our batch launcher class
If totally abandoning Spring Boot, I would need to adapt this launcher class but, being mostly used to XML Spring contexts, I find this a bit difficult.
// ...
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
@ComponentScan("my.config.package")
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
// ...
SpringApplication app = new SpringApplication(Application.class);
app.setWebEnvironment(false);
final Map<String, Object> maps = new HashMap<>();
maps.put("input", "file:" + inputPath);
app.setDefaultProperties(maps);
ConfigurableApplicationContext ctx = app.run(args);
JobExecutionSavingListener listener = ctx.getBean(JobExecutionSavingListener.class);
final JobExecution jobExecution = listener.getJobExecution();
if (jobExecution.getExitStatus() != ExitStatus.COMPLETED) {
System.exit(12);
return;
}
System.exit(0);
}
}
The question
What is the best way to change my code to adapt my Spring Batch application so that I could use my own Maven parent?
<scope>import</scope>
. I edited the question to match this new information. Maybe you could turn your comment into an answer, as it supplies the main elements of the answer. – Chop