SpringCloud注册与服务搭建

注册端

pom文件

版本用1.5.6.RELEASE

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
      <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-netflix-eureka-server</artifactId>
        </dependency>
         <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Dalston.SR4</spring-cloud.version>
    </properties>

启动类增加**@EnableEurekaServer**

@EnableEurekaServer
@SpringBootApplication
public class SpringcloudDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringcloudDemoApplication.class, args);
    }

}

application.yml

server:
  port: 8761
eureka:
  client:
    service-url:
      defalutZone: http://localhost:8761/eureka/
    fetch-registry: false
    register-with-eureka: false
通过访问localhost:8761出现如下

在这里插入图片描述

服务端

pom文件

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
	  <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>

启动类增加**@EnableDiscoveryClient*

@EnableDiscoveryClient
@SpringBootApplication
public class SpringcloudBbsApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringcloudBbsApplication.class, args);
    }

}

application.yml

spring:
  application:
    name: springcloud-bbs
server:
  port: 8080
eureka:
  instance:
    # 服务刷新时间配置,每隔这个时间会主动心跳一次
    # 默认30s
    lease-renewal-interval-in-seconds: 5
    # 服务过期时间配置,超过这个时间没有接收到心跳EurekaServer就会将这个实例剔除
    # 注意,EurekaServer一定要设置eureka.server.eviction-interval-timer-in-ms否则这个配置无效,这个配置一般为服务刷新时间配置的三倍
    # 默认90s
    lease-expiration-duration-in-seconds: 15
  server:
    ####关闭自我保护机制
    enable-self-preservation: false
    # 默认180s
    # eureka server缓存readWriteCacheMap失效时间,这个只有在这个时间过去后缓存才会失效,失效前不会更新,过期后从registry重新读取注册服务信息,registry是一个ConcurrentHashMap。
    # 由于启用了evict其实就用不太上改这个配置了
    response-cache-auto-expiration-in-seconds: 60
    # 启用主动失效,并且每次主动失效检测间隔为3s
    eviction-interval-timer-in-ms: 10000
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url:
      defaultZone: http://localhost:8761/eureka/

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值