赞
踩
前言:上一章节我们介绍了Eureka的基础,本章节则介绍Eureka服务端的安装与配置
Eureka架构原理图
效果图:
例:
- <?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">
- <parent>
- <artifactId>springcloud01</artifactId>
- <groupId>com.ken.springcloud</groupId>
- <version>1.0-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
-
- <artifactId>eureka-server7001</artifactId>
-
- <dependencies>
- <!--以下依赖都没写版本号,没写版本号的情况下会引用父项目的版本-->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- <!--监控-->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-actuator</artifactId>
- </dependency>
- <!--热部署-->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-devtools</artifactId>
- <scope>runtime</scope>
- <optional>true</optional>
- </dependency>
- <!--lombok插件-->
- <dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- <!--引入自己定义的api调用包,可以使用Payment模块的entity-->
- <dependency>
- <groupId>com.ken.springcloud</groupId>
- <artifactId>api-commons</artifactId>
- <version>${project.version}</version>
- </dependency>
- <!--Eureka Server-->
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
- </dependency>
- </dependencies>
- </project>
效果图:
如果application.yml不是绿色的,而是红色的,可以尝试install当前Maven工程,如果还不行可以尝试清除Idea的缓存
- server:
- port: 7001
- eureka:
- instance:
- #eureka服务端的实例名称
- hostname: localhost
- client:
- #false表示不向服务中心注册自己
- register-with-eureka: false
- #false表示自己端就是注册中心,只需要维护服务实例,并不需要检索服务
- fetch-registry: false
- service-url:
- #设置与Eureka Server交互的地址,查询服务和注册服务都需要依赖这个地址
- defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
效果图:
效果图:
- package com.ken.springcloud;
-
- import org.springframework.boot.SpringApplication;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
- import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
-
- @SpringBootApplication
- //标注为Eureka Server(服务注册中心)
- @EnableEurekaServer
- public class EurekaMain {
- public static void main(String[] args) {
- SpringApplication.run(EurekaMain.class, args);
- }
- }
效果图:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。