栏目分类:
子分类:
返回
终身学习网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
终身学习网 > IT > 软件开发 > 后端开发 > Java

SpringCloud项目搭建步骤

Java 更新时间:发布时间: 百科书网 趣学号
SpringCloud项目搭建步骤 springCloud五大核心组件

五大核心组件如下:

服务发现——Netflix Eureka客户端

负载均衡——Netflix Ribbon

断路器——Netflix Hystrix

服务网关——Netflix Zuul

分布式配置——Spring Cloud Config

一、搭建eureka客户端

1.新建一个SpringBoot项目
2.pom文件(springcloud版本需要与springboot版本对应。详情点击)



    4.0.0


    
        org.springframework.boot
        spring-boot-starter-parent
        2.4.2
         
    
    
    eureka-server
    eureka-server
    1.0-SNAPSHOT
    eureka-server
    Eureka Server project for Spring Boot
    
        1.8
        2020.0.5
    


    
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-server
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    
    
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                ${spring-cloud.version}
                pom
                import
            
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    


3.yml文件配置

server:
  port: 8761
eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka

4.启动类

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class, args);
    }
}

5.启动后访问可看到

二、导入项目(搭建项目)

1.项目pom文件(非全部,对应拷贝)


        org.springframework.boot
        spring-boot-starter-parent
        2.4.2

 
 		2020.0.5
  
    
  		
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-client
        
    
   	
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                ${spring-cloud.version}
                pom
                import
            
        
    

2.yml文件

server:
  port: 8762
  max-http-header-size: 10240
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
spring:
  application:
    name: xxx #注册中心名称,必填。

3.项目启动后注册中心可看到

feign

1.新建一个SpringBoot项目
2.pom文件



    4.0.0


    
        org.springframework.boot
        spring-boot-starter-parent
        2.4.2
         
    
    service-feign
        service-feign
        1.0-SNAPSHOT
    service-feign

    
        1.8
        2020.0.5
    


    
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-client
        
        
            org.springframework.cloud
            spring-cloud-starter-openfeign
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    
    
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                ${spring-cloud.version}
                pom
                import
            
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    

3.yml文件配置

server:
  port: 8765
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
spring:
  application:
    name: service-feign

4.启动类

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class ServiceFeignApplication {
    public static void main(String[] args) {
        SpringApplication.run(ServiceFeignApplication.class, args);
    }
}

5.启动后在注册中心可看到

转载请注明:文章转载自 www.051e.com
本文地址:http://www.051e.com/it/986790.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 ©2023-2025 051e.com

ICP备案号:京ICP备12030808号