Spring Cloud Alibaba 微服务生态基础实践

  • 打开pom.xml,下载依赖
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns=“http://maven.apache.org/POM/4.0.0” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

xsi:schemaLocation=“http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd”>

4.0.0

org.springframework.boot

spring-boot-starter-parent

2.2.9.RELEASE

nacos.democonsumer

sentinel

0.0.1-SNAPSHOT

sentinel

Demo project for Spring Boot

<java.version>1.8</java.version>

<spring-cloud-alibaba.version>2.2.1.RELEASE</spring-cloud-alibaba.version>

org.springframework.boot

spring-boot-starter-web

com.alibaba.cloud

spring-cloud-starter-alibaba-nacos-discovery

org.springframework.boot

spring-boot-starter-test

test

org.junit.vintage

junit-vintage-engine

com.alibaba.cloud

spring-cloud-alibaba-dependencies

${spring-cloud-alibaba.version}

pom

import

org.springframework.boot

spring-boot-maven-plugin

  • 设置项目配置文件:application.yml

端口

server:

port: 8083

spring:

application:

name: goods-service

cloud:

nacos服务注册

nacos:

discovery:

server-addr: 172.16.109.118:8848

  • 通过 Spring Cloud Alibaba原生注解 @EnableDiscoveryClient 开启服务注册发现功能

// 通过 Spring Cloud 原生注解 @EnableDiscoveryClient 开启服务注册发现功能

@EnableDiscoveryClient

@SpringBootApplication

public class DemoServiceApplication {

public static void main(String[] args) {

SpringApplication.run(DemoServiceApplication.class, args);

}

}

  • 建立HTTP接口的商品信息微服务,模拟返回商品列表

/**

  • 商品信息微服务-模拟返回商品列表

*/

@RestController

@RequestMapping(“api/goods”)

public class GoodsService {

public static final Logger logger = LoggerFact

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值