SpringCloud基于SpringBoot,是一系列框架组件的集合,为实现基于微服务的架构设计的。这里简单的使用Spring Cloud Eureka来实现服务治理。
1.在pom.xml中添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
2.在springboot工程的启动application类上加@EnableEurekaServer
注解
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
3.在application.yml
配置文件中添加registerWithEureka和fetchRegistry配置信息
rver:
port: 8761
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/