SpringCloud入门学习

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/
发布了120 篇原创文章 · 获赞 50 · 访问量 15万+

猜你喜欢

转载自blog.csdn.net/u014650759/article/details/103524141