Spring Cloud -- Eureka 单节点

本文详细介绍了SpringCloud环境下使用Eureka实现微服务架构的过程,包括Eureka服务端与客户端的搭建、配置及代码实现。通过具体示例,展示了如何在Win10系统上基于Java8和SpringCloud Greenwich.SR2版本,搭建并运行Eureka服务发现机制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Spring Cloud-Eureka

环境信息:
OS:Win10
JDK:Java8
SpringCloud:Greenwich.SR2

1 Eureka Server

1.1 核心依赖


        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>

1.2 开启注解


@SpringBootApplication
@EnableEurekaServer
public class CloudEurekaApplication {

	public static void main(String[] args) {
		SpringApplication.run(CloudEurekaApplication.class, args);
	}

}

1.3 主要配置

server:
  port: 8761

spring:
  application:
    name: cloud-eureka
  cloud:
    config:
      discovery:
        enabled: true

eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

1.4 Eureka服务端控制台

http://localhost:8761

在这里插入图片描述
服务端代码:https://github.com/WeisonWei/school-service-cloud/tree/master/cloud-eureka

2 Eureka Client

2.1 核心依赖


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

2.2 开启注解


@SpringBootApplication
@EnableEurekaClient
public class StudentServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(StudentServiceApplication.class, args);
    }

}

2.3 主要配置

spring:
  application:
    name: student-service

management:
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    health:
      show-details: always
    shutdown:
      enabled: true

eureka:
  client:
    registry-fetch-interval-seconds: 5
    healthcheck:
      enabled: true
    serviceUrl:
      defaultZone: http://localhost:8761/eureka

2.4 查看控制台服务注册情况

http://localhost:8761

在这里插入图片描述

客户端代码:https://github.com/WeisonWei/school-service/tree/master/student-service



参考资料:
[ 1 ].Spring Cloud 微服务实战 翟永超 电子工业出版社

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值