# eureka-web **Repository Path**: litepal/eureka-web ## Basic Information - **Project Name**: eureka-web - **Description**: eureka注册中心搭建 - **Primary Language**: Java - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-05-22 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Eureka注册中心搭建 ### 一、创建项目 ![创建项目1](https://gitee.com/litepal/eureka-web/raw/6dc19c0e4221c1a461c54fbf8a9c2eca9b7d2478/doc/eureka_1.png) ##### 1.1 创建spring boot项目 ![](https://gitee.com/litepal/eureka-web/raw/6dc19c0e4221c1a461c54fbf8a9c2eca9b7d2478/doc/eureka_2.png) ##### 1.2 配置项目信息 ![](https://gitee.com/litepal/eureka-web/raw/6dc19c0e4221c1a461c54fbf8a9c2eca9b7d2478/doc/eureka_3.png) ##### 1.3 选择Spring Cloud注册中心 ![](https://gitee.com/litepal/eureka-web/raw/6dc19c0e4221c1a461c54fbf8a9c2eca9b7d2478/doc/eureka_4.png) ### 二、配置application ``` package com.eureka.web; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.env.Environment; import java.net.InetAddress; import java.net.UnknownHostException; @EnableEurekaServer //添加注册中心服务注解 @SpringBootApplication public class EurekaWebApplication { public static void main(String[] args) throws UnknownHostException { ConfigurableApplicationContext application = SpringApplication.run(EurekaWebApplication.class, args); Environment env = application.getEnvironment(); String appName = env.getProperty("spring.application.name"); String host = InetAddress.getLocalHost().getHostAddress(); String port = env.getProperty("server.port"); System.out.println(appName + "访问路径:\nhttp://" + host + ":" + port); } } ``` ### 三、配置application.properties文件 ``` #应用名 spring.application.name=eureka-web #端口 server.port=1111 eureka.instance.hostname=localhost # 本应用为注册中心,设置false,表示不向注册中心注册自己 eureka.client.register-with-eureka=false # 注册中心的职责是维护服务实例,并不需要去检索服务,设置false eureka.client.fetch-registry=false # 替换注册中心默认服务路径,默认:String DEFAULT_URL = "http://localhost:8761/eureka/"; eureka.client.service-url.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/ ``` ### 四、启动注册中心 ``` eureka-web访问路径: http://192.168.0.38:1111 ``` ![](https://gitee.com/litepal/eureka-web/raw/6dc19c0e4221c1a461c54fbf8a9c2eca9b7d2478/doc/eureka_5.png) ### 五、源码 [https://gitee.com/litepal/eureka-web](https://gitee.com/litepal/eureka-web)