springboot集成consul 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
springcloud和springbootdiscovery:
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 = {"andata.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
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论