[Maven]–Module splitting, aggregation, inheritance, attributes, private server

1. Module development and design

Split each layer into a module and then modify the corresponding configuration file

Compile each module [compile] and install [install] to the local warehouse

Where needed, import it as a dependency in the pom.xml file

  • SSM_pojo split

    • Create a new module [no need to add a template]

    • Copy the corresponding relevant content in the original project to the SSM_pojo module

      • Entity class

      • Configuration file (none)

  • SSM_mapper split

    • New module

    • Copy the corresponding relevant content in the original project to the SSM_mapper module

      • Data access layer interface

      • Configuration files: Keep configuration files related to the data access layer (3)

        • Note: The paging plug-in is bound to SqlSessionFactoryBean in the configuration and needs to be retained.

      • pom.xml: Just introduce the coordinates related to the data access layer and delete the coordinates related to SpringMVC

        • spring

        • mybatis

        • spring integration mybatis

        • mysql

        • druid

        • pagehelper

        • Directly depends on SSM_pojo (execute the install command on the SSM_pojo module to install it to the local warehouse)

  • SSM_service split

    • New Project

    • Copy the corresponding relevant content in the original project to the SSM_service module

      • Business logic layer interface and implementation class

      • Configuration file: Keep configuration files related to the data access layer (1)

      • pom.xml: Just introduce the coordinates related to the data access layer and delete the coordinates related to SpringMVC

        • spring

        • junit

        • spring integration junit

        • Directly depends on SSM_mapper (execute the install command on the SSM_mapper module to install it into the local warehouse)

        • Indirect dependence on SSM_pojo (the SSM_mapper module is responsible for establishing dependencies)

      • Modify the service module spring core configuration file name, add the module name, format: applicationContext_service.xml

      • Modify the mapper module spring core configuration file name, add the module name, format: applicationContext_mapper.xml

      • Modify the name of the configuration file introduced by the unit test from a single file to multiple files

  • SSM_controller split

    • Create a new module [using webapp template]

    • Copy the corresponding relevant content in the original project to the SSM_controller module

      • Interface layer controller class and related setting class

      • Configuration files: retain configuration files related to the interface layer (1) and server-related configuration files (1)

      • pom.xml: Just introduce the coordinates related to the data access layer and delete the coordinates related to SpringMVC

        • spring

        • springmvc

        • jackson

        • servlet

        • tomcat server plug-in

        • Directly depends on SSM_service (execute the install command on the SSM_service module to install it into the local warehouse)

        • Indirect dependence on SSM_mapper, SSM_pojo

      • Modify the name of the configuration file that loads the spring environment in the web.xml configuration file, use the “*” wildcard character, and load all configuration files starting with applicationContext_

summary:

  • The module only contains the functional classes and configuration files corresponding to the current module

  • The spring core configuration is independently produced according to different functional modules.

  • The modules that the current module depends on can only be used after they are added to the current module in the form of imported coordinates.

  • web.xml needs to load all spring core configuration files

2. Aggregation

After the project is split into multiple modules, when one of the modules is modified and updated, the other modules do not know that it has been updated, which may cause errors.

Solution:

Add a module to control all other modules. When this module is run, other modules will also perform corresponding operations to solve the above problems. This is called aggregation.

Create a new project SSM [keep only the pom.xml file]

<!--Add the following code-->
<!--Define this module for build management-->
<packaging>pom</packaging>

<!--List of managed projects-->
<modules>
    <!--Specific project name-->
    <module>../ssm_pojo</module>
    <module>../ssm_mapper</module>
    <module>../ssm_service</module>
    <module>../ssm_controller</module>
</modules>

Note: The final execution order of modules participating in the aggregation operation is related to the dependencies between modules and has nothing to do with the configuration order.

3. Inheritance

The same dependency may be reused in sub-projects. If these dependencies are not managed, the versions of the same dependency in each sub-project may be inconsistent. In this case, the version management of each public dependency can be performed in the parent project, so that All dependency versions in the entire project are unified.

Add the following code to the pom.xml of the SSM project [parent project]

<dependencyManagement>
    <dependencies>
    <!--Write all dependencies that need to be managed here-->
    </dependencies>
</dependencyManagement>

Add the following code [subproject] to the module that uses the relevant dependencies

<!--Define the parent project of this project-->
<parent>
<groupId>org.example</groupId>
    <artifactId>ssm</artifactId>
    <!--Fill in the pom.xml file of the parent project-->
    <relativePath>.../ssm/pom.xml</relativePath>
</parent>

<!--The following two do not need to be written-->
<!--<groupId>com.qiuxuan</groupId>-->
<!--<version>1.0</version>-->
<!--The following two remain unchanged-->
<artifactId>project-java</artifactId>
<packaging>jar</packaging>
[Parent Project]
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>5.2.5.RELEASE</version>
</dependency>

【Subproject】
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
</dependency>

4. Properties

[Define custom attributes]
<properties>
<springmvc.version>5.2.5</springmvc.version>
</properties>

【use】
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>${springmvc.version}</version>
</dependency>

[Built-in attributes]
${basedir}
${version}

[setting attribute]
Use the tag attribute in the Maven configuration file setting.xml for dynamic configuration
${settings.localRepository}

[Java system properties]
${user.home}

System property query method
mvn help:system
${java.runtime.name} ===== Java(TM) SE Runtime Environment

================================================== =============================
System Properties
================================================== =============================

java.runtime.name=Java(TM) SE Runtime Environment
...

[Environment variable attributes]
Use the tag attribute in the Maven configuration file setting.xml for dynamic configuration
${env.JAVA_HOME}

Environment variable attribute query method
mvn help:system

================================================== =============================
Environment Variables
================================================== =============================

GATEWAY_VM_OPTIONS=D:\Software\ja-netfilter-all\vmoptions\gateway.vmoptions
......

5. Private server

【Nexus】

Download address: Downloadicon-default.png?t=N7T8https://help.sonatype.com/repomanager3/product-information/download

Install and start using the command line in the bin directory nexus /run nexus

Visit http://localhost:8081/

The port number can be modified in the etc directory

Warehouse Classification

  • Host repository hosted

    • Save resources that cannot be obtained from the central repository

      • Independent research and development

      • Third-party non-open source projects

  • proxy warehouse proxy

    • Proxy remote repository to access other public repositories such as central repository through Nexus

  • Warehouse group group

    • Group several warehouses into a group to simplify configuration

    • The warehouse group cannot save resources and is a design warehouse.

Downloading and uploading resources in the idea environment

Add to maven’s setting.xml file

<servers>
    <!--Configure permissions to access the Nexus server-->
    <server>
        <id>qiuxuan-release</id>
        <username>admin</username>
        <password>admin</password>
    <server>
    <server>
        <id>qiuxuan-snapshots</id>
        <username>admin</username>
        <password>admin</password>
   <server>
</server>
        
<mirrors>
<!--Configure the download image of a specific warehouse-->
<mirror>
<!--The unique identifier of this mirror, used to distinguish different mirror elements-->
<id>nexus-aliyun</id>
<!--Which kind of warehouse to mirror, simply put, it is to replace that warehouse-->
<mirrorOf>central</mirrorOf>
<!--Image name-->
<name>Nexus aliyun</name>
<!--Mirror URL-->
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
<!--Customized private server-->
<mirror>
<!--The unique identifier of this mirror, used to distinguish different mirror elements-->
<id>nexus-qiuxuan</id>
<!--Which kind of warehouse to mirror, simply put, it is to replace that warehouse-->
<mirrorOf>*</mirrorOf>
<!--Mirror URL-->
<url>http://localhost:8081/repository/maven-public/</url>
</mirror>
</mirrors>

[Add two warehouses to the server]

[Add two warehouses to the warehouse group]

[IDEA configuration upload component]

<!--Publish configuration-->
<distributionManagement>
    <repository>
        <id>qiuxuan-release</id>
        <url>http://localhost:8081/repository/qiuxuan-release/</url>
    </repository>
    <snapshotRepository>
        <id>qiuxuan-snapshots</id>
        <url>http://localhost:8081/repository/qiuxuan-snapshots/</url>
    </snapshotRepository>
</distributionManagement>

[Publish resources to private servers]

mvn deploy

One leaf knows autumn, mysteries and mysteries