Spring Cloud:第二章:eureka服务发现
服务注册中心 :eureka-server
新建一个springboot项目:eureka-server,其pom.xml配置如下:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
想要实现一个服务注册中心的功能非常简单,只需要在项目的启动类EurekaServerApplication上使用@EnableEurekaServer注解即可
1 @EnableEurekaServer
2 @SpringBootApplication
3 public class EurekaServerApplication{
4
5 public static void main(String[] args) {
6 new SpringApplicationBuilder(EurekaServerApplication.class)
7 .web(true).run(args);
8 }
9 }
默认情况下,该服务注册中心也会将自己作为客户端来尝试注册它自己,所以我们需要禁用它的客户端注册行为,只需要在application.properties配置文件中增加如下信息:
1 spring.application.name=eureka-server
2 server.port=1001
3 eureka.instance.hostname=localhost
4 eureka.client.register-with-eureka=false
5 eureka.client.fetch-registry=false
启动EurekaServerApplication,访问 http://localhost:9001/可以看到Eureka的页面,从红框的位置可以看到没有任务服务实例注册到当前的服务注册中心
更多内容请见原文,原文转载自:https://blog.csdn.net/weixin_44519496/article/details/120382471
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?