idea新建project
File->New->Project,选择Spring Initializr,设置相关信息,next
Eureka Server项目选择Eureka Server
Eureka Client项目选择Eureka Discovery
pom会自动配置相关依赖
Eureka Server配置:
server:
port: 8761
spring:
security:
user:
name: xxx
password: yyy
application:
name: @[email protected]
cloud:
config:
enabled: false
eureka:
instance:
hostname: eureka
prefer-ip-address: true
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://xxx:[email protected]${eureka.instance.hostname}:${server.port}/eureka/
server:
eviction-interval-timer-in-ms: 4000
enable-self-preservation: false
renewal-percent-threshold: 0.9
enable-self-preservation: false在生产环境改成true(默认为true)
注意:在启动的主类上加注解@EnableEurekaServer
Eureka Client配置:
spring:
application:
name: @[email protected]
eureka:
instance:
prefer-ip-address: true
client:
service-url:
defaultZone: http://xxx:[email protected]:8761/eureka/
注意:在启动的主类上加注解@EnableDiscoveryClient