Spring Cloud - 服务发现、注册、调用(一)

Spring Cloud - 服务发现、注册、调用

  • Spring Cloud - 服务发现、注册、调用(一)(eureka server)
  • Spring Cloud - 服务发现、注册、调用(二)(eureka client(provider))
  • Spring Cloud - 服务发现、注册、调用(三)(eureka client(consumer))

代码参见https://github.com/happut/springbootdemo

eureka server

用于服务注册、发现

建立springboot项目,增加spring-cloud-starter-eureka-server起步依赖:



    4.0.0

    com.github.happut
    springboot-demo-eureka-server
    0.0.1-SNAPSHOT
    jar

    springboot-demo-eureka-server
    Demo project for Spring Boot

    
        org.springframework.boot
        spring-boot-starter-parent
        1.5.8.RELEASE
         
    

    
        UTF-8
        UTF-8
        1.8
        Edgware.RELEASE
    

    
        
            org.springframework.cloud
            spring-cloud-starter-eureka-server
        
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.springframework.boot
            spring-boot-devtools
            runtime
        
        
            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
            
        
    




启动代码中增加@EnableEurekaServer

@SpringBootApplication
@EnableEurekaServer
public class SpringbootDemoEurekaServerApplication {

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

application.properties(yml请注意缩进)

server.port=1111

eureka.instance.hostname=localhost
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka

然后乐呵的启动就可以了:


Spring Cloud - 服务发现、注册、调用(一)_第1张图片
image.png

你可能感兴趣的:(Spring Cloud - 服务发现、注册、调用(一))