1 服务提供者
1.1 父级Pom
<spring-cloud.version>Hoxton.SR6</spring-cloud.version>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
1.2 Web
1.2.1 Pom
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
<optional>true</optional>
</dependency>
1.2.2 启动类
@EnableDiscoveryClient
1.2.3 配置文件
cloud:
consul:
host: 192.168.250.44
port: 8500
discovery:
register: true
serviceName: ${spring.application.name}
healthCheckPath:
/actuator/health
# healthCheckInterval: 1s
instanceId: ${spring.application.name}
ip-address: ${spring.cloud.client.ipaddress}
prefer-ip-address: true
1.3 Api
1.3.1 Pom
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR6</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<optional>true</optional>
</dependency>
1.3.2 接口样例
- Api
- Controller
2 服务消费者
2.1 父级Pom
<spring-cloud.version>Hoxton.SR6</spring-cloud.version>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
2.2 Web
2.2.1 Pom
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
<optional>true</optional>
</dependency>
2.2.2 启动类
@EnableFeignClients(basePackages = {"com.oceandata.od_idauth.api.*"})
2.2.3 配置文件
cloud:
consul:
host: 192.168.250.44
port: 8500
discovery:
register: false
serviceName: ${spring.application.name}
healthCheckPath: /actuator/health
instanceId: ${spring.application.name}
ip-address: ${spring.cloud.client.ipaddress}
prefer-ip-address: true