zoukankan      html  css  js  c++  java
  • 基于springcloud搭建项目-公共篇(二)

    上一篇已经写过如何搭建注册中心eureka,这一篇主要是搭建一些公共的api接口服务,并把实体类单独拿出来放到一个服务上引用,比较简单的

    1、首先。创建一个实体类服务,这样就不用在每个服务里创建实体了,只需要把实体的依赖加入到pom.xml中就可以引用,

    可以实现各服务间实体共享,这里的服务命名为study-entity,不需要添加任何配置,结构如下:

     2、在pom.xml中加入依赖,在依赖中要依赖父项目,这样一个封装实体的服务就创建好了

    <!--父项目依赖-->
    <parent>
            <groupId>com.study</groupId>
            <artifactId>study-cloud</artifactId>
            <version>1.0-SNAPSHOT</version>
            <relativePath>../study-cloud/pom.xml </relativePath><!-- lookup parent from repository -->
        </parent>
       
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
            </dependency>
            <dependency>
                <groupId>javax.persistence</groupId>
                <artifactId>persistence-api</artifactId>
                <version>1.0.2</version>
            </dependency>
        </dependencies>

    3、创建api服务,命名为study-api,主要是是用于管理接口,供其他服务之间可以相互调用,结构同上,不需要配置文件

     4、添加study-api的pom.xml依赖,引入父项目依赖,和实体依赖

        <!--父项目-->
        <parent>
            <groupId>com.study</groupId>
            <artifactId>study-cloud</artifactId>
            <version>1.0-SNAPSHOT</version>
            <relativePath>../study-cloud/pom.xml </relativePath><!-- lookup parent from repository -->
        </parent>
    <groupId>com.study</groupId> <artifactId>study-api</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>study-api</name> <description>Demo project for Spring Boot</description> <dependencies> <!--实体引入--> <dependency> <groupId>com.study</groupId> <artifactId>study-entity</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>

    5、最后,看下study-cloud父工程,创建项目时,以study-cloud作为父项目的都会在父项目中出现自动引入

     

     6、创建完成,这两个服务以后编码的过程中会用到,所以不想写测试代码,没有测试结果哦

  • 相关阅读:
    20145222黄亚奇《Java程序设计》第4周学习总结
    20145222黄亚奇《Java程序设计》第3周学习总结
    20145222黄亚奇《Java程序设计》第2周学习总结
    CodeForces
    2020 Multi-University Training Contest 3 1008 Triangle Collision
    Educational Codeforces Round 92 (Rated for Div. 2) E. Calendar Ambiguity
    2020 Multi-University Training Contest 3 1006 X Number
    2020 Multi-University Training Contest 3 1004 Tokitsukaze and Multiple
    2020 Multi-University Training Contest 2 1007 In Search of Gold
    2020 Multi-University Training Contest 1 1009 Leading Robots
  • 原文地址:https://www.cnblogs.com/jing5464/p/12206169.html
Copyright © 2011-2022 走看看