写在spring启动类上启动Eureka服务
@EnableEurekaServer
二、application.yml配置文件 1、服务端
server:
port: ${port:8761}
eureka:
client:
#Eureka客户端向Eureka服务端进行注册的地址。
service-url:
defaultZone: ${defaultZone:http://localhost:8762/eureka}
#向注册中心注册自己
register-with-eureka: true
#从注册中心拉取服务
fetch-registry: true
server:
# 检查失效服务的间隔时间.每隔60秒检测一次,把服务列表中超过90秒没有发送心跳续约服务进行剔除
eviction-interval-timer-in-ms: 60000
# 每分钟需要收到的续约次数的阈值,默认值就是:0.85
renewal-percent-threshold: 0.85
# 开启自我保护
enable-self-preservation: true
# 在获取不到服务时,需要等待的时间,默认5分钟,单位为毫秒,
wait-time-in-ms-when-sync-empty: 300000
spring:
application:
# 向注册中心进行注册的服务名称,不要使用下划线,不然启动会失败
name: eureka-server
2、客户端
server:
port: 9001
spring:
application:
name: cinema-portal-service
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka,http://localhost:8762/eureka
# 服务续约时间,每30秒发送一次心跳检测,证明自己还活着
lease-renewal-interval-in-seconds: 30
# 服务失效时间,默认90秒
lease-expiration-duration-in-seconds: 90
三、pom.xml依赖 1、eureka依赖 (1)父项目
(2)子项目org.springframework.cloud spring-cloud-dependencies2020.0.4 pom import
org.springframework.cloud spring-cloud-starter-netflix-eureka-server
四、安全认证 1、pom.xml依赖
2、配置类org.springframework.boot spring-boot-starter-security
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().ignoringAntMatchers("/eureka/**");
super.configure(http);
}
}
3、application.yml配置文件
(1)服务端
server:
port: ${port:8761}
eureka:
client:
#Eureka客户端向Eureka服务端进行注册的地址。
service-url:
defaultZone: ${defaultZone:http://nie:123@localhost:8762/eureka}
#不向注册中心注册自己
register-with-eureka: true
#不从注册中心拉取服务
fetch-registry: true
server:
# 检查失效服务的间隔时间.每隔60秒检测一次,把服务列表中超过90秒没有发送心跳续约服务进行剔除
eviction-interval-timer-in-ms: 60000
# 每分钟需要收到的续约次数的阈值,默认值就是:0.85
renewal-percent-threshold: 0.85
# 开启自我保护
enable-self-preservation: true
# 在获取不到服务时,需要等待的时间,默认5分钟,单位为毫秒,
wait-time-in-ms-when-sync-empty: 300000
spring:
application:
# 向注册中心进行注册的服务名称,不要使用下划线,不然启动会失败
name: eureka-server
security:
user:
name: nie
password: 123
(2)客户端
server:
port: 9001
spring:
application:
name: cinema-portal-service
eureka:
client:
service-url:
defaultZone: http://nie:123@localhost:8761/eureka,http://nie:123@localhost:8762/eureka
# 服务续约时间,每30秒发送一次心跳检测,证明自己还活着
lease-renewal-interval-in-seconds: 30
# 服务失效时间,默认90秒
lease-expiration-duration-in-seconds: 90



