最近需要搭建个注册中心,其中遇到几个问题记录一下:
首先再idea创建maven项目,接着
1.引入eureka依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
2.增加启动类
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer
@SpringBootApplication
public class AppEureka {
public static void main(String[] args) {
SpringApplication.run(AppEureka.class,args);
}
}
3.增加配置文件application.yml
<?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/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>eureka</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>2.2.3.RELEASE</version>
</dependency>
</dependencies>
</project>
依赖大功告成了就要,启动报错如下
怀疑是版本问题更换版本,
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>2.1.2.RELEASE</version>
启动,报错,看样子是缺少了com.google.code.gson包,引入
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.6</version>
</dependency>
大功告成,访问localhost:8100
注册服务到注册中心几个配置说明:
eureka:
instance:
status-page-url-path: /actuator/info
health-check-url-path: /actuator/health
home-page-url-path: /
#使用IP注册
prefer-ip-address: true
instance-id: ${spring.cloud.client.ip-address}:${server.port}
hostname: ${spring.cloud.client.ip-address}
appname: riskcheck
# 服务续约(心跳)频率,单位:秒,缺省30
lease-renewal-interval-in-seconds: 30