原文地址: https://blog.csdn.net/qq_36666651/article/details/82728336
本文主要简单讲述了spring cloud组件简单集成的配置及代码(只有简单使用方法,没有原理之类的讲解)。
代码github地址:https://github.com/wkcaeser/spring-cloud-demo/tree/master
Netflix-eureka
eureka server
eureka server主要提供服务注册和发现的功能
依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
配置文件:
spring:
application:
name: eurekaserver1
profiles: peer1 # profiles名称, 启动时可通过spring.profiles.active=peer1来指定该配置文件
server:
port: 8000
eureka:
instance:
hostname: peer1
#Eureka实例的状态页面和健康指示器默认情况下分别用"/info"和"/health"代表
statuspageUrlPath: ${management.context-path}/info}
healthCheckUrlPath: ${management.context-path}/health}
client:
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
fetch-registry: true # 是否从eureka server获取注册信息, 默认 true
register-with-eureka: true # 是否将自己注册到eureka server, 默认 true
启动类上加上@EnableEurekaServer注解:
@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
------------------------------------------------------------------------------------------------------------
eureka-client
依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
配置:
spring.application.name=eureka-client
server.port=9091
# 对外访问地址
eureka.instance.hostname=www.wk02.com
# 服务注册地址
eureka.client.service-url.defaultZone=http://www.wk01.com:9081/eureka/
------------------------------------------------------------------------------------------------------------
netflix-ribbon