新建Eureka server和client

1.首先来建一个Eureka server

然后是配置文件application.yml

server:
  port : 9993
  ip: localhost
#注册中心配置
eureka:
  instance:
    hostname : localhost
  client:
    registerWithEureka : false #属性表示是否将自己注册到Eureka Server, 默认为true。 由于当前应用就是Eureka Server, 因此设为 false;
    fetchRegistry : false #表示是否从Eureka Server获取注册信息,默认为true。 如果这是一个单点的 Eureka Server,不需要同步其他节点的数据,可以设为false。
    serviceUrl:
#      defaultZone: http://eureka-server-peer52:8761/eureka/
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
  server:
    enableSelfPreservation: false # 测试时关闭自我保护机制,保证不可用服务及时踢出
    evictionIntervalTimerInMs: 4000  #清理间隔(单位毫秒,默认是60*1000)

然后再启动类上面加上注解@EnableEurekaServer

@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication {
	public static void main(String[] args) {
		SpringApplication.run(EurekaServerApplication.class, args);
	}

}

然后启动,就可以用http://localhost:9993/去访问了,下面是还没有client的样子

接下我们来建一个client

 

application.yml

server:
  port: 8888
eureka:
  client:
    serviceUrl:
      defaultZone : http://localhost:9993/eureka/

spring:
  application:
    name : demo3

启动类加上注解@EnableDiscoveryClient

@EnableDiscoveryClient
@SpringBootApplication
public class Demo3Application {

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

}

 

到这么,本以为都ok了,但是,我启动报错了。

Completed shut down of DiscoveryClient
 ERROR 4376 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

The Tomcat connector configured to listen on port 8888 failed to start. The port may already be in use or the connector may be misconfigured.

Action:

Verify the connector's configuration, identify and stop any process that's listening on port 8888, or configure this application to listen on another port.

百度到时说要在pom文件中加载

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
</dependency>

说是缺失启动容器。参考链接:https://blog.csdn.net/CodeFarmer_/article/details/80592388(评论里面别人问原因)

然后启动,哦了,

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值