• springcloud工程建立 父工程+公用子模块+微服务提供模块


    1. 建立 Java Working Set:工程多的时候可以展开收缩,方便管理

      切换到Package Explorer视图,并点击视图右侧下箭头,选择Working Sets,如下图:

    2. 建立父工程,将后续子工程公共的Jar包提出来:
      • 选择Working Set,右键New -> Maven Project:
      • 选择 Create a simple project,点击下一步

      • 创建父工程,父工程名称:thrcloud,Packaging:选择pom

      • 父工程建立完成,修改pom.xml文件:


        pom.xml文件内容如下,springcloud和springboot的版本可以选择比较新的版本对应关系,我这里比较旧:

        <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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
            <modelVersion>4.0.0</modelVersion>
            <groupId>com.thr.springcloud</groupId>
            <artifactId>thrcloud</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <packaging>pom</packaging>
        
            <properties>
                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                <maven.compiler.source>1.8</maven.compiler.source>
                <maven.compiler.target>1.8</maven.compiler.target>
                <junit.version>4.12</junit.version>
                <log4j.version>1.2.17</log4j.version>
                <lombok.version>1.18.4</lombok.version>
            </properties>
        
            <dependencyManagement>
                <dependencies>
                    <dependency>
                        <groupId>org.springframework.cloud</groupId>
                        <artifactId>spring-cloud-dependencies</artifactId>
                        <version>Dalston.SR1</version>
                        <type>pom</type>
                        <scope>import</scope>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-dependencies</artifactId>
                        <version>1.5.9.RELEASE</version>
                        <type>pom</type>
                        <scope>import</scope>
                    </dependency>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>8.0.14</version>
                    </dependency>
                    <dependency>
                        <groupId>com.alibaba</groupId>
                        <artifactId>druid</artifactId>
                        <version>1.0.31</version>
                    </dependency>
                    <dependency>
                        <groupId>org.mybatis.spring.boot</groupId>
                        <artifactId>mybatis-spring-boot-starter</artifactId>
                        <version>1.3.0</version>
                    </dependency>
                    <dependency>
                        <groupId>ch.qos.logback</groupId>
                        <artifactId>logback-core</artifactId>
                        <version>1.2.3</version>
                    </dependency>
                    <dependency>
                        <groupId>junit</groupId>
                        <artifactId>junit</artifactId>
                        <version>${junit.version}</version>
                        <scope>test</scope>
                    </dependency>
                    <dependency>
                        <groupId>log4j</groupId>
                        <artifactId>log4j</artifactId>
                        <version>${log4j.version}</version>
                    </dependency>
                </dependencies>
            </dependencyManagement>
        
        </project>
        View Code
    3. 建立公共子模块 thrcloud-api:

      • 鼠标右键 thrcloud -> New -> Other

      • 选择 Maven Module


      • 创建了如下子模块工程 thrcloud-api,同时 thrcloud父工程的pom.xml文件也有所变化:
      • 修改 thrcloud-api工程的pom.xml文件,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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
          <modelVersion>4.0.0</modelVersion>
          
          <parent>    <!-- 子类里面显示申明才能有明确的继承表现,无意外就是父类的默认版本,否则自己定义 -->
            <groupId>com.thr.springcloud</groupId>
            <artifactId>thrcloud</artifactId>
            <version>0.0.1-SNAPSHOT</version>
          </parent>
          
          <artifactId>thrcloud-api</artifactId>    <!-- 当前Module我自己叫什么名字 -->
          
          <dependencies><!-- 当前Module需要用到的jar包,按自己需求添加,如果父类已经包含了,可以不用写版本号 -->
                  <!-- 用作自动隐式生成Entity的构造函数、get set方法、链式访问风格 -->
                <dependency>
                    <groupId>org.projectlombok</groupId>
                    <artifactId>lombok</artifactId>
                </dependency>
            </dependencies>
        </project>
        View Code
    4. 建立服务提供者模块 thrcloud-provider-user-8001 用户为服务提供者 Module
      • 选中 thrcloud 右键 -> New -> Maven Module ,如下图:
      • thrcloud-provider-user-8001工程如下图:
      • 修改 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
            <modelVersion>4.0.0</modelVersion>
            <parent>
                <groupId>com.thr.springcloud</groupId>
                <artifactId>thrcloud</artifactId>
                <version>0.0.1-SNAPSHOT</version>
            </parent>
        
            <artifactId>thrcloud-provider-user-8001</artifactId>
        
            <dependencies>
                <dependency><!-- 引入自己定义的api通用包,可以使用Dept部门Entity -->
                    <groupId>com.thr.springcloud</groupId>
                    <artifactId>thrcloud-api</artifactId>
                    <version>${project.version}</version>
                </dependency>
                <dependency>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </dependency>
                <dependency>
                    <groupId>mysql</groupId>
                    <artifactId>mysql-connector-java</artifactId>
                </dependency>
                <dependency>
                    <groupId>com.alibaba</groupId>
                    <artifactId>druid</artifactId>
                </dependency>
                <dependency>
                    <groupId>ch.qos.logback</groupId>
                    <artifactId>logback-core</artifactId>
                </dependency>
                <dependency>
                    <groupId>org.mybatis.spring.boot</groupId>
                    <artifactId>mybatis-spring-boot-starter</artifactId>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-jetty</artifactId>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-test</artifactId>
                </dependency>
                <!-- 修改后立即生效,热部署 -->
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>springloaded</artifactId>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-devtools</artifactId>
                </dependency>
            </dependencies>
        
        </project>
        View Code
      • 手动建立主启动类 UserProvider8001_App.java,如下图:

        到此完成!

  • 相关阅读:
    vs2019+GLFW+GLAD出现无法解析的外部符号
    图的着色算法
    Head First C# 实验室2(冒险游戏)
    击中和击不中变换
    开运算和闭运算
    膨胀与腐蚀
    两数相加(C#数据结构和算法练习)
    C# 特性和索引(C#学习笔记06)
    C# 索引器(C#学习笔记05)
    C# yield checked,unchecked lock语句(C#学习笔记04)
  • 原文地址:https://www.cnblogs.com/smartbear/p/11562985.html
Copyright © 2020-2023  润新知