SpringCloud————创建服务提供者

在eureka-demo父工程下创建了eureka-client模块,配置pom文件引入Eureka客户端和SpringBoot相关依赖。主启动类使用@EnableDiscoveryClient注解以启用Eureka客户端功能,并设置配置文件连接Eureka服务器。启动eureka-client后,它成功注册到预先运行的eureka-server中。
摘要由CSDN通过智能技术生成

创建eureka-client模块

在上一篇中的eureka-demo父工程上创建eureka-client模块
在这里插入图片描述

编写pom文件

<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.lzh</groupId>
        <artifactId>eureka-demo</artifactId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>

    <artifactId>eureka-client</artifactId>
    <packaging>jar</packaging>
    <name>eureka-client</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
        	<!-- Eureka 客户端依赖 -->
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</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-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

编写主启动类

@SpringBootApplication
//eureka客户端注解
@EnableDiscoveryClient
public class EurekaClientApplication {
    public static void main(String[] args) {
        new SpringApplicationBuilder(EurekaClientApplication.class)
                .web(WebApplicationType.SERVLET)
                .run(args);
    }
}

创建配置文件

spring:
  application:
    name: eureka-client
server:
  port: 30000
eureka:
  client:
    service-url:
      # eureka 服务端地址
      defaultZone: http://localhost:20000/eureka/
  instance:
    instance-id: eureka-client

启动

先运行上篇我们创建的注册中心,eureka-server,运行成功后,再启动eureka-client的主启动类,启动完成后,访问eureka-server。
在这里插入图片描述
得到如上界面,在Instances currently registered with Eureka中有我们刚刚创建的client的注册信息,说明我们启动并注册成功。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值