文章目录
注册端
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/