Springboot+Maven is an architectural model that separates startup classes from business modules

In previous projects, the startup class has always been at the same level as the Controller, Service, Mapper and other packages. Maven just imports other modules or third-party Jar package tools.
But the structure of the latest set of projects that I took over is very interesting. I also want to record and share it, and directly upload the schematic diagram:

insert image description here

According to the traditional mode, each submodule of ABC will have its own startup class. But in current mode:

There are five Maven projects in the figure above. The parent module contains four sub-modules. One of the sub-modules is the startup class responsible for starting the sub-module of ABC. Among the three sets of sub-modules of ABC, there are their own packages of controller, service, and mapper. However, the package name paths of the controllers that only need the three submodules of ABC are the same (⚠️It is best to keep the same, otherwise the configuration of this case will not scan the controller!! Assume it is com.jojo.zoo), then the startup class specifies the scanning path. written as:

@SpringBootApplication(scanBasePackages = {
    
    "com.jojo.zoo"})

Then, in the pom file of the startup class module, all the ABC modules need to be introduced.

If you don't want to start the class module to directly import ABC, then import ABC in the parent module:

<dependencyManagement>
	<dependencies>
		<dependency>
			<groupId>com.jojo.zoo</groupId>
			<artifactId>jojo-A</artifactId>
			<version>${
    
    jojo.version}</version>
		</dependency>

		<dependency>
			<groupId>com.jojo.zoo</groupId>
			<artifactId>jojo-B</artifactId>
			<version>${
    
    jojo.version}</version>
		</dependency>

		<dependency>
			<groupId>com.jojo.zoo</groupId>
			<artifactId>jojo-C</artifactId>
			<version>${
    
    jojo.version}</version>
		</dependency>
	</dependencies>
</dependencyManagement>
The module of the parent module must contain ABC and startup class modules
<modules>
	<module>jojo-start</module>
	<module>jojo-A</module>
	<module>jojo-B</module>
	<module>jojo-C</module>
</modules>
This makes it easier to manage the corresponding version in a unified manner, and then add it to the pom of the XXX-Starter startup module:
<dependencies>
	<dependency>
		<groupId>com.jojo.zoo</groupId>
		<artifactId>jojo-A</artifactId>
	</dependency>

	<dependency>
		<groupId>com.jojo.zoo</groupId>
		<artifactId>jojo-B</artifactId>
	</dependency>

	<dependency>
		<groupId>com.jojo.zoo</groupId>
		<artifactId>jojo-C</artifactId>
	</dependency>
</dependencies>

In this way, it can be started normally, and all the Controllers under the ABC three modules are scanned.

Why is it split like this?

The boss said that the startup class is not used during deployment, so there is no need to package that piece of code at all, and the splitting is more neat and clean; at the same time, the corresponding modules can be combined more flexibly, and the module code is more separated.

Finally, remember to brush maven, clean + install in any case

Guess you like

Origin blog.csdn.net/whiteBearClimb/article/details/124756584