If your project has multiple batches, you have the option of putting multiple batches in one project, splitting them into multiple projects, and so on. In this article, I tried the former approach of putting multiple batches in one project and separating the Main class.
>gradle -v
------------------------------------------------------------
Gradle 6.5
------------------------------------------------------------
Build time: 2020-06-02 20:46:21 UTC
Revision: a27f41e4ae5e8a41ab9b19f8dd6d86d7b384dad4
Kotlin: 1.3.72
Groovy: 2.5.11
Ant: Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM: 11.0.2 (Oracle Corporation 11.0.2+9)
OS: Windows 10 10.0 amd64
STS 3.9.9.RELEASE (I have to make it a sloppy 4 system ...)
multiple-main └src/main/java └com/example/dem ├MultipleApplication.java └MultipleApplication2.java
When you try to execute Spring Application, the screen to select the Main class will appear as shown in the figure below, so select the one you want to execute.
After loading the application plug-in, specify the mainClass. It's inconvenient because you have to rewrite build.gradle one by one. (Reference link 1)
plugins {
id 'org.springframework.boot' version '2.3.5.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
id 'application'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
mainClassName = "com.example.demo.MultipleMainApplication2"
repositories {
mavenCentral()
}
java -cp multiple-main-0.0.1-SNAPSHOT.jar -Dloader.main=com.example.demo.MultipleMainApplication org.springframework.boot.loader.PropertiesLauncher
(Reference link 2)
PropertiesLauncher is Who? However, even if the mainClass of build.gradle is MultipleMainApplication2, I was able to start MultipleMainApplication (unmarked).
It's not impossible, but I felt it was awkward. In the Main class, it is difficult to handle beans under Spring management (it is not impossible to handle), so if you want to put multiple processes in one project, I think that it is better to switch Runner by referring to the following article. (This method was also adopted in the field).
Recommended Posts