摘要:本文主要向大家介绍了JAVA语言的Spring cloud Eureka注册中心搭建的方法,通过具体的实例让大家了解,希望对大家学习JAVA语言有所帮助。
本文主要向大家介绍了JAVA语言的Spring cloud Eureka注册中心搭建的方法,通过具体的实例让大家了解,希望对大家学习JAVA语言有所帮助。
前提
系统安装jdk1.8及以上,配置好maven的ide(这里用idea进行演示,maven版本3.5,配置阿里云源)
项目搭建
新建一个maven项目,创建最简单的那种就好,项目名这里为EurekaServerDemo,包名什么的随意,项目打包方式为jar,
也可以使用spring官方的生成器,官方的生成器会创建基础的springboot项目结构。这里为了演示,都可以
修改pom文件,参考如下,版本推荐和本文相同,springboot和cloud版本的坑很多
<project xmlns="//maven.apache.org/POM/4.0.0" xmlns:xsi="//www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="//maven.apache.org/POM/4.0.0 //maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.hellxz EurekaServerDemo 0.0.1-SNAPSHOT jar org.springframework.cloud spring-cloud-netflix-eureka-server 1.3.5.RELEASE EurekaServerDemo Demo project for Spring Boot org.springframework.boot spring-boot-starter-parent 1.5.9.RELEASE org.springframework.cloud spring-cloud-dependencies Camden.SR3 pom import org.springframework.cloud spring-cloud-config-server org.springframework.cloud spring-cloud-starter-eureka-server org.springframework.boot spring-boot-starter-actuator org.springframework.boot spring-boot-maven-plugin org.apache.maven.plugins maven-compiler-plugin 1.8 1.8
复制代码
新建一个主类,用于启动项目
package com.hellxz.EurekaServerDemo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; /** * @Author : Hellxz * @Description: EurekaServer * @Date : 2018/4/13 16:53 */ @EnableEurekaServer @SpringBootApplication public class EurekaServerDemoApplication { public static void main(String[] args) { //启动这个springboot应用 SpringApplication.run(EurekaServerDemoApplication.class,args); } }
复制代码
在resources目录下新建一个application.properties文件,用于配置EurekaServer相关参数,也可以使用yaml文件
#提供服务端口
server.port=1111
#提供服务的域名,本地可以使用localhost或者配置hosts测试
eureka.instance.hostname=localhost
#关闭向注册中心注册自己
eureka.client.register-with-eureka=false
#关闭发现注册服务,注册中心仅用于维护节点
eureka.client.fetch-registry=false
#配置注册中心提供服务的url(这里引用上边的配置)
eureka.client.serviceUrl.defaultZone=//${eureka.instance.hostname}:${server.port}/eureka/
复制代码
启动这个项目测试一下
测试
因为配置的是localhost:1111作为访问路径,这里启动项目后直接访问就好,如图
至此Eureka注册中心搭建完毕
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注编程语言JAVA频道!
擅长针对企业软件开发的产品设计及开发的细节与流程设计课程内容。座右铭:大道至简!
已有23人表明态度,87%喜欢该老师!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号