父工程搭建完毕后,接下来要搭建注册中心,所有的服务都要通过注册中心注册发现,才能进行调用。
new ->maven Project ->create a simple project 父工程选择之前建立的parent工程
修改pom.xml文件
<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>
<parent>
<groupId>org.joey</groupId>
<artifactId>baymin-cloud-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>baymin-cloud-eureka</artifactId>
<name>baymin-cloud-eureka</name>
<description>服务注册中心</description>
<!--声明编码版本,和java版本 -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<!--springboot项目maven打包插件 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!--指定项目的main方法 -->
<configuration>
<mainClass>org.joey.baymin.BayminEurekaApplication</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<!--依赖库 -->
<repositories>
<repository>
<id>aliyun</id>
<name>aliyun</name>
<url>https://maven.aliyun.com/repository/public</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<!--注册中心服务端 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<!--注册中心客户端 -->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.0.6</version>
</dependency>
</dependencies>
</project>
创建springboot启动类
@EnableEurekaServer
@SpringBootApplication
public class BayminEurekaApplication {
//服务中心
public static void main(String[] args) {
SpringApplication.run(BayminEurekaApplication.class, args);
}
}
添加
@EnableEurekaServer
@SpringBootApplication
两个注解,表示这是springboot类型的注册中心
添加application.properties配置文件
spring.profiles.active=dev
spring.application.name=plisp-eureka-server
server.port=8761
eureka.instance.hostname=localhost
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/
# 关闭自我保护模式(缺省为打开)
eureka.server.enable-self-preservation=false
# 续期时间,即扫描失效服务的间隔时间(缺省为60*1000ms)
eureka.server.eviction-interval-timer-in-ms=5000
spring.boot.admin.client.url=http://192.168.0.6:8760
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
spring.boot.admin.client.instance.prefer-ip=true
dev里面
spring.boot.admin.client.url=http://127.0.0.1:8760
启动注册中心服务类
输入地址 127.0.0.1:8761 进入注册中心服务端
如此 注册中心搭建完毕。