2019年第一篇blog打算从微服务开始,正所谓自己立下的flag趴着也要写完^^.所以从今天开始打算会持续写Spring-Cloud相关文章.
因为单体用用存在一些问题,总结归纳如下:
打开idea,选择创建Spring项目
选择Maven坐标:gav
选择项目类型为Eureka-Server
创建完项目之后,查看Pom中Spring-Cloud与Boot版本:
<!-- spring-boot版本 --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.1.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <!-- spring-cloud版本 --> <properties> <java.version>1.8</java.version> <spring-cloud.version>Greenwich.RC1</spring-cloud.version> </properties> 复制代码
@SpringBootApplication @EnableEurekaServer public class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); } } 复制代码
eureka: client: service-url: defaultZone: http://localhost:8762/eureka/,http://localhost:8763/eureka/ register-with-eureka: false spring: application: name: eureka-server server: port: 8761 复制代码
Eureka-Server2的配置文件如下:
spring: application: name: eureka-server2 server: port: 8762 eureka: client: service-url: defaultZone: http://localhost:8761/eureka/,http://localhost:8763/eureka/ register-with-eureka: false 复制代码
Eureka-Server3的配置文件如下:
spring: application: name: eureka-server3 server: port: 8763 eureka: client: register-with-eureka: false service-url: defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/ 复制代码
配置说明:
到这里,我们集群式的Eureka-Server已经搭建好了, 我们下一节来搭建Eureka-Client来发现服务.好了,预知后事如何, 请听下回分解!