请教一个spring cloud consul 服务注册与发现的问题!

PS: 编辑器上传图片好像有问题!
贴不了客户端失败的照片了
下面贴一下我的代码
pox.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/ma ... gt%3B
<modelVersion>4.0.0</modelVersion>

<groupId>com.merlin</groupId>
<artifactId>spring-consul-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>spring-consul-client</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Dalston.SR3</spring-cloud.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>


</project

application.propertis 文件
server.port=8855
spring.application.name=consul-client
spring.cloud.consul.host=localhost
spring.cloud.consul.port=8500
spring.cloud.consul.enabled=true
spring.cloud.consul.discovery.enabled=true
spring.cloud.consul.discovery.instanceId=tomcat2
spring.cloud.consul.discovery.serviceName=tomcat
spring.cloud.consul.discovery.hostname=localhost
spring.cloud.consul.discovery.port=${server.port}
spring.cloud.consul.discovery.healthCheckUrl=http://localhost:8855/health
spring.cloud.consul.discovery.healthCheckInterval=10s
spring.cloud.consul.discovery.tags=test

management.security.enabled=false
启动类文件:
package com.merlin.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@EnableDiscoveryClient
@RestController
public class SpringConsulClientApplication {

@Autowired
private LoadBalancerClient loadBalancer;

@Autowired
private DiscoveryClient discoveryClient;

/**
* 从所有服务中选择一个服务(轮询)
*/
@RequestMapping("/discover")
public Object discover() {
return loadBalancer.choose("tomcat").getUri().toString();
}

/**
* 获取所有服务
*/
@RequestMapping("/services")
public Object services() {
return discoveryClient.getInstances("tomcat");
}

@RequestMapping("/hello")
public String hello() {
return "hello";
}

public static void main(String args) {
SpringApplication.run(SpringConsulClientApplication.class, args);
}
}


 
ps:而且我发现/health端点也有问题,查看不了consul 的健康信息。
已邀请:

Levin丶挽歌 - 胆小认生,不易相处

赞同来自:

从代码看 没啥大毛病 , 是否有日志

要回复问题请先登录注册