Eureka与SpringCloud简单使用
Eureka-Server篇
1.在pom.xml中添加eureka
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
2.在启动类中添加@EnableEurekaServer
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
3.在application.yml中进行一些属性的配置
server:
port: 8761
eureka:
instance:
hostname: localhost
instance-id: ${spring.application.name}:${vcap.application.instance_id:${spring.application.instance_id:${random.value}}}
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka
server:
wait-time-in-ms-when-sync-empty: 0
enable-self-preservation: false
spring:
application:
name: eureka-server