微服务
程序员文章站
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/