Spring Cloud 系列笔记总目录:Spring Cloud 学习笔记
consul和zookeeper是啥就不说了,只贴核心配置
Consul
依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
启动类
@SpringBootApplication
@EnableDiscoveryClient //该注解用于向使用consul或者zookeeper作为注册中心时注册服务
public class OrderZKMain80
{
public static void main(String[] args) {
SpringApplication.run(OrderZKMain80.class, args);
}
}
配置文件
cloud:
consul:
host: localhost
port: 8500
discovery:
service-name: ${
spring.application.name}
loadbalancer:
ribbon:
enabled: false
Zookeeper
依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
<!--先排除自带的zookeeper 因为可能导致冲突-->
<exclusions>
<exclusion>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--添加zookeeper3.4.9版本-->
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.9</version>
</dependency>
配置文件
server:
port: 8004 # 注册到zookeeper服务器的支付服务提供者端口号
spring:
application:
name: cloud-provider-payment
cloud:
zookeeper:
connect-string: localhost:2181 #zookeeper服务的地址
启动类
@SpringBootApplication
@EnableDiscoveryClient //该注解用于向使用consul或者zookeeper作为注册中心时注册服务
public class OrderZKMain80
{
public static void main(String[] args) {
SpringApplication.run(OrderZKMain80.class, args);
}
}