1.搭建EurekaServer
springboot版本
2.1.3.RELEASE
springcloud版本
Greenwich.SR1
(1)创建一个springboot项目
注意:勾选EurekaServer支持
(2)application.yml配置文件
server:
port: 7776
eureka:
client:
service-url:
defaultZone: http://localhost:7776/eureka/
fetch-registry: false
register-with-eureka: false
register-with-eureka:是否注册自身到eureka服务器,因为当前这个应用就是eureka服务器,没必要注册自身,所以这里是false.
fethch-registry是否从eureka服务器获取注册信息,同上,这里不需要
(3)在启动类上加
@EnableEurekaServer
注解
就这么简单,一个euerka服务就搭好了,可以访问http://localhost:7776
2.搭建EurekaClient
(1)创建springboot项目
注意:勾选Eureka Discovery
(2)application.yml配置文件
server:
port: 7777
eureka:
client:
service-url:
defaultZone: http://localhost:7776/eureka/
spring:
application:
name: eureka-client
(3)在启动类上加
@EnableDiscoveryClient
这样eurekaDiscovery就创建好了,注意:上面创建项目的时候没有添加web支持,这样会导致项目无法启动,所以要加入web依赖,
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
这样就没问题了
好了,今天就是一个简单的入门,就到这里,明天在这个基础上加入
spring-boot-starter-security
安全认证,再作一个springcolud基于restfull的远程调用小栗子