【Java】consul 服务一直注册失败
在springcloud中,我想用consul作为注册中心,但是服务一直注册都是失败的
我的配置文件是这样的
server:port: 9100
###服务的名字
spring:
application:
name: mzd-consul-member
cloud:
consul:
##配置consul的ip和端口
host: 127.0.0.1
port: 8500
discovery:
##配置这个服务的ip地址
hostname: 127.0.0.1
server:port: 9200
###服务的名字
spring:
application:
name: mzd-consul-order
cloud:
consul:
##配置consul的ip和端口
host: 127.0.0.1
port: 8500
discovery:
##配置这个服务的ip地址
hostname: 127.0.0.1
pom文件:
<!--管理依赖 --><dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.M7</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.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>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<!--注意:这里必须要添加,否则各种依赖有问题 -->
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
启动类:
@SpringBootApplication@EnableDiscoveryClient
public class ConsulorderApplication {
public static void main(String[] args) {
SpringApplication.run(ConsulorderApplication.class, args);
}
@Bean
@LoadBalanced
public RestTemplate getRestTemplate() {
return new RestTemplate();
}
}
请问一下,为什么一直注册不成功呢?难道consul需要其他操作吗。我eureka和zookeeper都能注册成功。。。
回答
以上是 【Java】consul 服务一直注册失败 的全部内容, 来源链接: utcz.com/a/89758.html