文章目录
Eureka服务端开发
- Eureka服务端开发
- yml
- 启动类
- 测试
- 首先在tensequare_parent中锁定springcloud的版本 在其pom文件中添加信息如下
org.springframework.cloud
spring-cloud-dependencies
Finchley.M9
pom
import
- 创建tensquare_eureka模块 在其pom文件中,添加如下的eureka的依赖
org.springframework.cloud
spring-cloud-starter-netflix-eureka-server
yml
在tensquare_eureka模块的application.yml中 填写如下的信息
server:
port: 6868 # eureka服务端口
eureka:
client:
register-with-eureka: false # 当前服务无需注册到eureka中
fetch-registry: false # 无需从eureka中获取注册信息
service-url: #Eureka客户端与Eureka服务端进行交互的地址
defaultZone: http://127.0.0.1:${server.port}/eureka/
启动类
在com.tensquare.eureka.EurekaServer路径中,创建启动类 主要要在启动类中,加上@EnableEurekaServer注解
package com.tensquare.eureka;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
/**
* 类名称:EurekaServer
* 类描述:Eureka的启动类
*
* @author: taohongchao
* 创建时间:2019/2/16 16:50
* Version 1.0
*/
@SpringBootApplication
@EnableEurekaServer
public class EurekaServer {
public static void main(String[] args){
SpringApplication.run(EurekaServer.class);
}
}
测试
启动tensquare_eureka项目.进行测试 启动完成后,在浏览器中输入如下地址 http://localhost:6868/
出现如下的信息,代表eureka服务搭建成功