Springcloud框架搭建
来源:互联网 发布:关于套路的网络用语 编辑:程序博客网 时间:2024/06/05 17:50
//首先创建注册方的配置
//第一点,添加pop.xml依赖
<dependency> <groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Dalston.SR1</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>//第二步,在application.properties配置服务注册中心spring.application.name=server-register-centerserver.port=1111eureka.instance.hostname=localhosteureka.client.register-with-eureka=falseeureka.client.fetch-registry=false//第三步,在DemoApplication中添加注解@EnableEurekaServer
//在服务方的配置
//第一点,添加pop.xml依赖
<!--服务提供方的依赖包--> <dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka</artifactId> </dependency><dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Brixton.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
//第二步,在application.properties配置
#spring cloud配置spring.application.name=simple-service-providerserver.port=2222eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/
//第三步,在DemoApplication中添加注解
@EnableDiscoveryClient
//在controller中的简约配置
@RequestMapping("/plus/{a}/{b}") public Integer plus(@PathVariable Integer a, @PathVariable Integer b){ return a+b; }
//配置消费方的配置
//也是先添加pop.xml
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-feign</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Brixton.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
//第二步,在application.properties配置
spring.application.name=simple-service-consumerserver.port=3333eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/
//第三步,在DemoApplication中添加注解
//注解在DemoApplication类上@EnableDiscoveryClient//在类里面 @Bean public RestTemplate restTemplate() { return new RestTemplate(); }
//消费方controller
@Autowired private LoadBalancerClient lbc; @Autowired private RestTemplate template; @RequestMapping("/comsumer/{a}/{b}") public String computePlus(@PathVariable Integer a, @PathVariable Integer b){ //发现服务 ServiceInstance choose = lbc.choose("simple-service-provider"); String url = "http://" + choose.getHost() + ":" + choose.getPort() + "/plus/"+a+"/"+b; Integer result = template.getForObject(url, Integer.class); return a+"+"+b+"="+result; }
省下的就是对各个服务的添加其他的操作
阅读全文
0 0
- Springcloud框架搭建
- 利用SpringCloud搭建一个最简单的微服务框架
- 利用SpringCloud搭建一个最简单的微服务框架
- 利用SpringCloud搭建一个最简单的微服务框架
- springCloud搭建,启动bug
- 搭建SpringCloud服务配置中心
- 微服务框架-SpringCloud简介
- SpringCloud(一) 跟着博文学搭建
- SpringCloud Config-----1、搭建分布式配置中心
- 使用SpringCloud搭建微服务<一>
- SpringCloud 项目基础搭建与使用
- SpringCloud之注册中心Eureka搭建-亲测好用
- SpringCloud注册中心高可用搭建
- SpringCloud配置中心高可用搭建
- springcloud之搭建高可用的eureka
- springcloud- maven 模块化搭建soa项目
- springcloud《二》--搭建第一个Eureka程序
- SpringCloud用zookeeper搭建配置中心
- sql日期格式化
- ORACLE冷备文件恢复
- ArrayBlockingQueue源码分析
- shiro快速入门
- 解决websocket中localhost改为ip地址连接不上
- Springcloud框架搭建
- 连接企业无线网络时需要频繁输入用户密码的解决办法
- latex中局部使用中文环境
- 汇总统计数据工具—你所不知道的arcgis工具
- Why is ARKit better than the alternatives?
- Python网络数据采集——正则表达式
- 53. Maximum Subarray (dp)
- 剑指offer_递归与循环---变态跳台阶
- Python 解压压缩包