微服务之快速搭建Eureka Server
来源:互联网 发布:安卓java游戏大全 编辑:程序博客网 时间:2024/06/06 06:59
Spring Cloud Eureka可以快速实现服务注册与发现,这在微服务项目中非常有意义。
接下来配合IntelliJ使用Spring Cloud框架+maven来从头搭建一个Eureka Server工程:
1. New Project -> Spring Initializr,之后可以一路next。
创建成功后可以看到如下的项目结构:
2. 修改pom.xml文件,添加必要依赖包:
<?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>com.deng.site</groupId> <artifactId>eurekaserver</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>eurekaserver</name> <description>Eureka server</description> <parent> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-parent</artifactId> <version>Camden.SR7</version> </parent> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies></project>
其中spring-cloud-starter-eureka-server即是eureka server必需的包,其他spring相关依赖包由parent继承。
3. 修改application.properties
server.port=8761eureka.instance.hostname=127.0.0.1eureka.instance.prefer-ip-address=trueeureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/eureka.client.registerWithEureka=falseeureka.client.fetchRegistry=false
说明:
eureka.client.registerWithEureka: 为false意味着自身仅作为服务器,不作为客户端;
eureka.client.fetchRegistry: 为false意味着无需注册自身。
4. 修改启动类,并运行
修改EurekaServerApplication类,添加@EnableEurekaServer注解,然后运行。
@SpringBootApplication@EnableEurekaServerpublic class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); }}
最后访问127.0.0.1:8761,看到如下页面说明EurekaServer启动成功:
接下来会介绍Eureka Client配合Eureka Server的使用。
源码地址:https://github.com/LeiDengDengDeng/MySite中的eurekaserver。
阅读全文
0 0
- 微服务之快速搭建Eureka Server
- spring boot 通过Eureka搭建微服务
- 微服务之Eureka服务发现
- spring cloud之Eureka Server环境搭建
- SpringCloud(四):将微服务注册到Eureka Server
- SpringBoot--将微服务注册到Eureka Server上
- MicroService4Net快速搭建微服务
- Eureka Server 搭建部署
- 微服务基础设施之服务注册中心: Spring Cloud Eureka
- Spring Cloud微服务(2)之 注册中心Eureka
- spring cloud 微服务之 Eureka与Feign
- 高可用eureka server搭建
- spring cloud eureka-server搭建
- MicroService4Net快速搭建微服务(二)
- 如何快速搭建一个微服务架构?
- 10分钟快速搭建本地微服务
- 如何快速搭建一个微服务架构?
- Spring-boot:快速搭建微服务框架
- 浏览器中的 ES6 module 实现
- 数组元素比大小的出错点
- docker 安装
- 安装openssh for window
- 一个苦逼程序员日常的 10 个扎心瞬间
- 微服务之快速搭建Eureka Server
- 程序员这高薪岗位只有计算机专业的能做?
- 程序员进阶的这五个瞬间,你到哪个阶段了?
- 干货!程序员进好公司的面试技巧
- Spring Boot Cache + redis 设置有效时间和自动刷新缓存,时间支持在配置文件中配置
- 宏和函数
- vue-cli工程化
- 互联网并发编程之一 线程安全03线程中的脏读
- Fatal error in launcher: Unable to create process using 错误解决 以及python3安装scrapy