欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

微服务

程序员文章站 2022-06-03 20:19:52
...

Docker

 

 

Springboot

Eureka服务

SpringCould提供对Netflix Eureka(服务注册和发现工具),所有服务都被Eukera服务列出和发现,从Spring配置读取

①添加maven依赖

<!--添加服务-->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-eureka</artifactId>
		</dependency>

②启动类添加注解

@SpringBootApplication
@EnableEurekaServer
public class App {

    /**
     *
     * @param args
     */
    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}

③server端配置 src/main/resources/application.yml

# Yureka Server Configuration
server:
  port: ${vcap.application.port:8761}   # HTTP port

eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
  server:
    waitTimeInMsWhenSyncEmpty: 0

# Discovery Server Dashboard uses FreeMarker.  Don't want Thymeleaf templates
spring:
  thymeleaf:
    enabled: false     # Disable Thymeleaf

④客户端配置 src/main/resources/application.yml

# Discovery Server Access
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/