• IDEA 部署spring Cloud


    Spring cloud Eureka

    Eureka Server,注册中心

    Eureka Client,所有要进行注册的微服务通过Eureka Client 连接到 Eureka Server ,完后注册

    一.创建父工程,pom.xml

    <modelVersion>4.0.0</modelVersion>

    <groupId>com.southwind</groupId>
    <artifactId>aispringcloud</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <modules>
    <module>eurekaserver</module>
    <module>eurekaclient</module>
    </modules>

    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.3.RELEASE</version>
    </parent>
    <dependencies>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <!--解决 jdk 9 以上没有 jaxb api 的问题-->
    <!--<dependency>-->
    <!--<groupId>javax.xml.bind</groupId>-->
    <!--<artifactId>jaxb-api</artifactId>-->
    <!--<version>2.3.0</version>-->
    <!--</dependency>-->
    <!--<dependency>-->
    <!--<groupId>com.sun.xml.bind</groupId>-->
    <!--<artifactId>jaxb-impl</artifactId>-->
    <!--<version>2.3.0</version>-->
    <!--</dependency>-->
    <!--<dependency>-->
    <!--<groupId>com.sun.xml.bind</groupId>-->
    <!--<artifactId>jaxb-core</artifactId>-->
    <!--<version>2.3.0</version>-->
    <!--</dependency>-->
    <!--<dependency>-->
    <!--<groupId>javax.activation</groupId>-->
    <!--<artifactId>activation</artifactId>-->
    <!--<version>1.1.1</version>-->
    <!--</dependency>-->
    <dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.6</version>
    <scope>provided</scope>
    </dependency>

    </dependencies>

    <dependencyManagement>
    <dependencies>
    <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-dependencies</artifactId>
    <version>Finchley.SR2</version>
    <type>pom</type>
    <scope>import</scope>
    </dependency>
    </dependencies>
    </dependencyManagement>
    2.然后在父类里面创建两个子工程

    在第一个子项目中创建配置文件 application.yml 添加EUREKA Server相关配置

    #端口号
    server:
    port: 7070
    #是否在注册中心把自己当成一个微服务注册
    eureka:
    client:
    register-with-eureka: false
    fetch-registry: false
    service-url:
    defaultZone: http://localhost:9090/eureka/
    属性说明:
    server.por:当前Eureka Server 服务端口
    eureka.client.register-with-eureka:是否将当前的Eureka Server 服务作为客户端进行注册
    eureka.client.fetch-fegistry:是否获取其他Eureka Server 服务的数据
    eureka.client.service-url.defaultzone:注册中心访问地址
    性对应的pom.xml的配置:
    <parent>
    <artifactId>aispringcloud</artifactId>
    <groupId>com.southwind</groupId>
    <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>eurekaserver</artifactId>
    <!--注册中心-->
    <dependencies>
    <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    <version>2.0.2.RELEASE</version>
    </dependency>
    </dependencies>
    .创建启动类
    @SpringBootApplication     //声明该类是springboot的入口
    @EnableEurekaServer //声明该类少一个Eureka Server微服务,提供注册和发现功能(注册中心
    public class EurekaServerApplication {
    public static void main(String[] args){
    SpringApplication.run(EurekaServerApplication.class,args);
    }
    }
    ####### Eureka Client代码的实现
    1.创建 Module,pom.xml
    第二个子项目中 pom.xml 的配置 yml 配置 启动类配置
    <parent>
    <artifactId>aispringcloud</artifactId>
    <groupId>com.southwind</groupId>
    <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>eurekaclient</artifactId>

    <dependencies>
    <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    <version>2.0.2.RELEASE</version>
    </dependency>
    </dependencies>

    yml的配置:
    server:
    port: 9090
    # 当前服务器注册在Eureka Server上面的名字
    spring:
    application:
    name: provider
    # 注册中心访问的地址
    eureka:
    client:
    service-url:
    defaultZone: http://localhost:9090/eureka/
    # 是否将当前服务的ip注册到 Eureka Server
    instance:
    prefer-ip-address: true

    实体类:
    package com.ssouthwind;

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;

    /**
    * Created by 86182 on 2019/7/29.
    */
    @SpringBootApplication
    public aspect ProviderAppliaction {
    public static void main(String[] args){
    SpringApplication.run(ProviderAppliaction.class,args);
    }
    }
     
    
    
  • 相关阅读:
    BZOJ-4008: [HNOI2015]亚瑟王 (概率期望DP)
    BZOJ-4832: [Lydsy2017年4月月赛]抵制克苏恩 (概率期望DP)
    BZOJ-1415: [Noi2005]聪聪和可可 (期望DP)
    BZOJ2425 [HAOI2010]计数
    BZOJ2424 [HAOI2010]订货
    BZOJ2423 [HAOI2010]最长公共子序列
    BZOJ2299 [HAOI2011]向量
    BZOJ2298 [HAOI2011]problem a
    BZOJ1040 [ZJOI2008]骑士
    BZOJ一天提交(AC) 51纪念
  • 原文地址:https://www.cnblogs.com/shxkey/p/11263189.html
Copyright © 2020-2023  润新知