spring cloud (二) 服务提供者 EuekaClient

1 创建一个springboot项目  spring-cloud-service-a  注册到eureka服务注册中心中

 项目添加依赖

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>

 

2 启动类添加注解

@EnableDiscoveryClient

@SpringBootApplication
@EnableDiscoveryClient
public class SpringCloudServiceAApplication {

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

3 配置文件添加

#指定服务名称

spring.application.name=service-a

#注册服务
eureka.client.service-url.defaultZone=http://localhost:8080/eureka/

 

4 编写一个controller 

@RestController
public class TestController {
    @GetMapping("/getm")
    public String getMessage(String message) {
        return "hello world:"+message;
    }
}

 

5 启动服务,eureka注册中心会有这个服务

 

posted @ 2018-10-02 23:11  冬天不眠  阅读(275)  评论(0编辑  收藏  举报