从0到1带大家搭建spring cloud alibaba 微服务大型应用框架(三) (mini-cloud) 搭建认证服务(认证/资源分离版) oauth2.0 (中)

  • 9
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
Spring Cloud Alibaba是一个以Spring Cloud为基础的微服务开发框架,它提供了一站式的微服务解决方案,包括服务注册与发现、配置心、消息总线、负载均衡、断路器、数据监控等组件,同时还提供了阿里间件的支持,例如阿里云的RocketMQ、分布式事务解决方案Seata等。使用Spring Cloud Alibaba可以快速搭建分布式应用系统,提高开发效率和系统可靠性。 下面是一个使用Spring Cloud Alibaba实现微服务的例子: 1.添加依赖 ```xml <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <version>2.2.3.RELEASE</version> </dependency> ``` 2.配置文件 ```yaml spring: application: name: service-provider cloud: nacos: discovery: server-addr: localhost:8848 # Nacos服务注册心地址 ``` 3.编写服务提供者 ```java @RestController public class HelloController { @GetMapping("/hello") public String hello() { return "Hello, World!"; } } ``` 4.启动服务提供者 ```java @SpringBootApplication @EnableDiscoveryClient public class ServiceProviderApplication { public static void main(String[] args) { SpringApplication.run(ServiceProviderApplication.class, args); } } ``` 5.编写服务消费者 ```java @RestController public class HelloController { @Autowired private RestTemplate restTemplate; @GetMapping("/hello") public String hello() { String url = "http://service-provider/hello"; return restTemplate.getForObject(url, String.class); } } ``` 6.启动服务消费者 ```java @SpringBootApplication @EnableDiscoveryClient public class ServiceConsumerApplication { @Bean @LoadBalanced public RestTemplate restTemplate() { return new RestTemplate(); } public static void main(String[] args) { SpringApplication.run(ServiceConsumerApplication.class, args); } } ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

峡谷电光马仔

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值