Spring Cloud(一) 创建服务提供者

  • 通过Spring Initializr快速创建SpringBoot项目

Spring Initializr 在eclipse、idea等开发工具都有插件支持,还可以自行访问 http://start.spring.io/使用。

  • 引入Spring boot依赖

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
</parent>

  • 引入actuator依赖,提供端点监控服务

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

  • 引入spring cloud的依赖 目前选用Edgware版本

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Edgware.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

  • 编写实现

源码下载:https://gitee.com/sansan-33/spring-cloud-study.git   

模块:san3-provider-user

  • 运行结果

rest api:http://localhost:8000/1

{"id":1,"username":"account1","name":"张三","age":20,"balance":100.00}

actuator health : http://localhost:8000/health

{"status":"UP","diskSpace":{"status":"UP","total":106198724608,"free":78122856448,"threshold":10485760},"db":{"status":"UP","database":"H2","hello":1}}

actuator info:http://localhost:8000/info

{"app":{"name":"san3-provider-user","encoding":"UTF-8","java":{"source":"10.0.1","target":"10.0.1"}}}

  • 引入eureka服务端依赖

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

  • 注册服务

aplication.yml中加入注册配置,如:

eureka:
  client:
    serviceUrl:
      defaultZone: http://[用户名]:[密码]@ip:port/eureka/

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值