前文:https://mp.csdn.net/postedit/101777094
前文我们提到要搭建一个完整的微服务框架,我们需要实现三个部分:已实现服务的注册,注册中心的创建,已注册服务的调用。
我们现在已经创建了一个简单服务,本文中将完成注册中心的创建以及服务的注册。
SpringCloud只能选择Eureka作为注册机。
第一步:
打开IDEA-New-Project:
选择Spring Initializr:
这次只需要选择Eureka Server
然后完成创建。
第二步:
给主函数(刚创建好唯一的那个)添加Eureka注解:
package com.eurekaserver.eurekaserver1;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class Eurekaserver1Application {
public static void main(String[] args) {
SpringApplication.run(Eurekaserver1Application.class, args);
}
}
第三步:
给application.properties添加Eureka启动参数:
server.port=1111
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://yourip*****:${server.port}/eureka/
然后启动即可