Spring Cloud 项目搭建(一)

Eureka 注册中心

1.新建一个注册中心项目;将eureka-service包导入该项目。

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

2.给该项目创建一个.yaml 文件,因为eureka是默认自动注册的所以需要,设置取消默认注册。并且设置端口号

server:
  port: 8761

eureka:
  client:
    register-with-eureka: false #由于Eureka项目是注册中心所以,不需要进行注册,将register-with-eureka 设置成 false ; fetch-registry 设置成 false
    fetch-registry: false
    service-url:
      defaultZone: http://localhost:8761/eureka/

在这里插入图片描述

在创建 Erueka项目是遇到了两个问题:

  1. 在注册中心使用 Eureka-client 包.项目不会提示错误,但是访问Eureka注册中心时会报404.该错误只需要将 包换成 eureka-server 就好了且 application中注册
@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication{
    
    
}
  1. 运行成功,但后面接着Unregistering application xxx with eureka with status DOWN。
    原因是,我没有添加Web 库添加 Spring web库后就没有出现这样的错误。
<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

猜你喜欢

转载自blog.csdn.net/weixin_42789301/article/details/107216005