Spring Cloud project construction (1)

Eureka Registry

1. Create a new registry project; import the eureka-service package into the project.

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

2. Create a .yaml file for the project, because eureka is automatically registered by default, so it needs to be set to cancel the default registration. And set the port number

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/

Insert picture description here

Two problems were encountered when creating the Erueka project:

  1. Use the Eureka-client package in the registry. The project will not prompt an error, but it will report a 404 when accessing the Eureka registry. The error only needs to be changed to eureka-server and registered in the application
@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication{
    
    
}
  1. The operation was successful, but Unregistering application xxx with eureka with status DOWN followed.
    The reason is that I did not add the web library after adding the Spring web library and there was no such error.
<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

Guess you like

Origin blog.csdn.net/weixin_42789301/article/details/107216005