如何新建注册中心微服务:
可以直接用idea新建工程以sping initializer选择
建议使用jdk8 ,建议使用springboot 2.0以上
选择spring web,eureka server 。
以下是pom文件依赖:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.barry</groupId>
<artifactId>euraka</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>euraka</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>2020.0.3</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</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>
需配置启动类注解:
@EnableEurekaServer
添加配置文件:
server:
port: 8080 #访问端口
eureka:
server:
enable-self-preservation: false # 关闭自我保护模式(缺省为打开)
instance:
hostname: spring-cloud-euraka #实例名称 可在后续由feingn调用时作为地址部分
client:
service-url: #
defaultZone: http://127.0.0.1:8080/eureka #多个的话以,隔开
register-with-eureka: false # 不向eureka server 注册自己
fetch-registry: false # 不向eureka server 获取服务列表
spring:
application:
name: spring-cloud-euraka #应用名称,不可有下划线。
启动,进入界面。
如图,显示euraka界面则说明启动注册中心成功。
详细列表说明这里不再赘述,网上有很多教程。
附件代码上传:
https://download.csdn.net/download/yssz001/19483419