父子工程搭建

1. 构建父工程

父工程的职责是对依赖包的版本进行管理,创建父工程分两步,第一创建父工程,第二在pom.xml编辑依赖管理。

进入新建模块界面,选择Spring Initializr,填写模块的信息:

创建成功,删除多余文件:

2、依赖管理定义

父工程中没有代码,不用去依赖其它的包,它的作用是限定其它子工程依赖包的版本号,即在dependencyManagement中去编辑即可。

1)确定父工程为一个pom工程,在pom.xml中添加如下内容:

<packaging>pompackaging>

2)编辑依赖的包的版本号、打包插件等。

pom.xml如下:


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0modelVersion>
    <groupId>com.xuechenggroupId>
    <artifactId>xuecheng-plus-parentartifactId>
    <version>0.0.1-SNAPSHOTversion>
    <name>xuecheng-plus-parentname>
    <description>xuecheng-plus-parentdescription>
    <packaging>pompackaging>

    <properties>
        <java.version>1.8java.version>
        <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8project.reporting.outputEncoding>
        <spring-boot.version>2.3.7.RELEASEspring-boot.version>
        <spring-cloud.version>Hoxton.SR9spring-cloud.version>
        <org.mapstruct.version>1.3.1.Finalorg.mapstruct.version>
        <spring-cloud-alibaba.version>2.2.6.RELEASEspring-cloud-alibaba.version>
        <org.projectlombok.version>1.18.8org.projectlombok.version>
        <javax.servlet-api.version>4.0.1javax.servlet-api.version>
        <fastjson.version>1.2.83fastjson.version>
        <druid-spring-boot-starter.version>1.2.8druid-spring-boot-starter.version>
        <mysql-connector-java.version>8.0.30mysql-connector-java.version>
        <mybatis-plus-boot-starter.version>3.4.1mybatis-plus-boot-starter.version>
        <commons-lang.version>2.6commons-lang.version>
        <minio.version>8.4.3minio.version>
        <xxl-job-core.version>2.3.1xxl-job-core.version>
        <swagger-annotations.version>1.5.20swagger-annotations.version>
        <commons-lang3.version>3.10commons-lang3.version>
        <okhttp.version>4.8.1okhttp.version>
        <swagger-spring-boot-starter.version>1.9.0.RELEASEswagger-spring-boot-starter.version>
        <elasticsearch.version>7.12.1elasticsearch.version>
    properties>


    <dependencyManagement>
        <dependencies>

            <dependency>
                <groupId>org.springframework.cloudgroupId>
                <artifactId>spring-cloud-dependenciesartifactId>
                <version>${spring-cloud.version}version>
                <type>pomtype>
                <scope>importscope>
            dependency>
            <dependency>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-dependenciesartifactId>
                <version>${spring-boot.version}version>
                <type>pomtype>
                <scope>importscope>
            dependency>
            <dependency>
                <groupId>com.alibaba.cloudgroupId>
                <artifactId>spring-cloud-alibaba-dependenciesartifactId>
                <version>${spring-cloud-alibaba.version}version>
                <type>pomtype>
                <scope>importscope>
            dependency>
            
            <dependency>
                <groupId>org.projectlombokgroupId>
                <artifactId>lombokartifactId>
                <version>${org.projectlombok.version}version>
            dependency>
            
            <dependency>
                <groupId>org.mapstructgroupId>
                <artifactId>mapstruct-jdk8artifactId>
                <version>${org.mapstruct.version}version>
            dependency>
            <dependency>
                <groupId>org.mapstructgroupId>
                <artifactId>mapstruct-processorartifactId>
                <version>${org.mapstruct.version}version>
            dependency>
            <dependency>
                <groupId>io.swaggergroupId>
                <artifactId>swagger-annotationsartifactId>
                <version>${swagger-annotations.version}version>
            dependency>
            
            <dependency>
                <groupId>javax.servletgroupId>
                <artifactId>javax.servlet-apiartifactId>
                <version>${javax.servlet-api.version}version>
                <scope>providedscope>
            dependency>
            
            <dependency>
                <groupId>com.alibabagroupId>
                <artifactId>fastjsonartifactId>
                <version>${fastjson.version}version>
            dependency>
            
            <dependency>
                <groupId>com.alibabagroupId>
                <artifactId>druid-spring-boot-starterartifactId>
                <version>${druid-spring-boot-starter.version}version>
            dependency>

            
            <dependency>
                <groupId>mysqlgroupId>
                <artifactId>mysql-connector-javaartifactId>
                <version>${mysql-connector-java.version}version>
            dependency>
            
            <dependency>
                <groupId>com.baomidougroupId>
                <artifactId>mybatis-plus-boot-starterartifactId>
                <version>${mybatis-plus-boot-starter.version}version>
            dependency>

            
            <dependency>
                <groupId>com.baomidougroupId>
                <artifactId>mybatis-plus-generatorartifactId>
                <version>${mybatis-plus-boot-starter.version}version>
            dependency>

            
            <dependency>
                <groupId>commons-langgroupId>
                <artifactId>commons-langartifactId>
                <version>${commons-lang.version}version>
            dependency>
            
            <dependency>
                <groupId>io.miniogroupId>
                <artifactId>minioartifactId>
                <version>${minio.version}version>
            dependency>
            
            <dependency>
                <groupId>com.google.guavagroupId>
                <artifactId>guavaartifactId>
                <version>25.0-jreversion>
            dependency>
            
            <dependency>
                <groupId>com.xuxueligroupId>
                <artifactId>xxl-job-coreartifactId>
                <version>${xxl-job-core.version}version>
            dependency>
            
            <dependency>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-starter-testartifactId>
                <version>${spring-boot.version}version>
                <scope>testscope>
                <exclusions>
                    <exclusion>
                        <groupId>org.junit.vintagegroupId>
                        <artifactId>junit-vintage-engineartifactId>
                    exclusion>
                exclusions>
            dependency>
            <dependency>
                <groupId>com.squareup.okhttp3groupId>
                <artifactId>okhttpartifactId>
                <version>${okhttp.version}version>
            dependency>
            <dependency>
                <groupId>org.apache.commonsgroupId>
                <artifactId>commons-lang3artifactId>
                <version>${commons-lang3.version}version>
            dependency>
            <dependency>
                <groupId>com.spring4allgroupId>
                <artifactId>swagger-spring-boot-starterartifactId>
                <version>${swagger-spring-boot-starter.version}version>
            dependency>
            <dependency>
                <groupId>org.elasticsearch.clientgroupId>
                <artifactId>elasticsearch-rest-high-level-clientartifactId>
                <version>${elasticsearch.version}version>
            dependency>

            <dependency>
                <groupId>org.elasticsearchgroupId>
                <artifactId>elasticsearchartifactId>
                <version>${elasticsearch.version}version>
            dependency>
        dependencies>

    dependencyManagement>

    <build>
        <finalName>${project.name}finalName>
        
        <resources>
            <resource>
                <directory>src/main/resourcesdirectory>
                <filtering>truefiltering>
                <includes>
                    <include>**/*include>
                includes>
            resource>
            <resource>
                <directory>src/main/javadirectory>
                <includes>
                    <include>**/*.xmlinclude>
                includes>
            resource>
        resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-compiler-pluginartifactId>
                <version>3.8.1version>
                <configuration>
                    
                    <source>1.8source>
                    
                    <target>1.8target>
                    
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombokgroupId>
                            <artifactId>lombokartifactId>
                            <version>${org.projectlombok.version}version>
                        path>
                    annotationProcessorPaths>
                configuration>
            plugin>

            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-resources-pluginartifactId>
                <version>3.3.0version>
                <configuration>
                    <encoding>utf-8encoding>
                    
                    <useDefaultDelimiters>trueuseDefaultDelimiters>
                configuration>
            plugin>
        plugins>
    build>
project>

2. 构建子工程

1、首先在项目根目录创建内容管理模块的父工程xuecheng-plus-content:

创建完成,只保留pom.xml文件,删除多余的文件。

内容管理父工程的主要职责是聚合内容管理接口和内容管理接口实现两个工程,它的父工程是xuecheng-plus-parent。


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0modelVersion>
    <parent>
        <artifactId>xuecheng-plus-parentartifactId>
        <groupId>com.xuechenggroupId>
        <version>0.0.1-SNAPSHOTversion>
        <relativePath>../xuecheng-plus-parentrelativePath>
    parent>
    <artifactId>xuecheng-plus-contentartifactId>
    <name>xuecheng-plus-contentname>
    <description>xuecheng-plus-contentdescription>
    <packaging>pompackaging>

  <modules>
    <module>xuecheng-plus-content-apimodule>
    <module>xuecheng-plus-content-modelmodule>
    <module>xuecheng-plus-content-servicemodule>
   modules>
project>

2、在其下创建model数据模型工程。

创建完成,只保留包和pom.xml文件,删除多余的文件。


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0modelVersion>
    <parent>
        <artifactId>xuecheng-plus-contentartifactId>
        <groupId>com.xuechenggroupId>
        <version>0.0.1-SNAPSHOTversion>
    parent>
    <artifactId>xuecheng-plus-content-modelartifactId>
    <dependencies>
                <dependency>
            <groupId>com.xuechenggroupId>
            <artifactId>xuecheng-plus-baseartifactId>
            <version>0.0.1-SNAPSHOTversion>
        dependency>
    dependencies>
project>

3、在其下创建service接口实现工程。

创建完成,只保留包和pom.xml文件 ,删除多余的文件


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0modelVersion>
    <parent>
        <artifactId>xuecheng-plus-contentartifactId>
        <groupId>com.xuechenggroupId>
        <version>0.0.1-SNAPSHOTversion>
    parent>
    <artifactId>xuecheng-plus-content-serviceartifactId>
        <dependencies>
        <dependency>
            <groupId>com.xuechenggroupId>
            <artifactId>xuecheng-plus-content-modelartifactId>
            <version>0.0.1-SNAPSHOTversion>
        dependency>
     dependencies>
project>
4、在其下创建api接口工程。

xuecheng-plus-content-api接口工程的父工程是xuecheng-plus-content,它依赖了xuecheng-plus-base基础工程。


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0modelVersion>
    <parent>
        <artifactId>xuecheng-plus-contentartifactId>
        <groupId>com.xuechenggroupId>
        <version>0.0.1-SNAPSHOTversion>
    parent>
    <artifactId>xuecheng-plus-content-apiartifactId>
    <dependencies>
        <dependency>
            <groupId>com.xuechenggroupId>
            <artifactId>xuecheng-plus-content-serviceartifactId>
            <version>0.0.1-SNAPSHOTversion>
        dependency>
    dependencies>
project>

你可能感兴趣的:(微服务,java)