package com.yonyou;
import java.net.URI;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
/**
* @author Administrator
*
*/
@EnableDiscoveryClient //通过该注解,实现服务发现,注册
@SpringBootApplication
public class EurekaClientApplication {
/**
* LoadBalanced 注解表明restTemplate使用LoadBalancerClient执行请求
*/
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
RestTemplate template = new RestTemplate();
SimpleClientHttpRequestFactory factory = (SimpleClientHttpRequestFactory) template.getRequestFactory();
factory.setConnectTimeout(3000);
factory.setReadTimeout(3000);
return template;
}
public static void main(String[] args) {
SpringApplication.run(EurekaClientApplication.class, args);
}
}
@RestController
class ServiceInstanceRestController {
@Autowired
@LoadBalanced
RestTemplate restTemplate;
@Autowired
private DiscoveryClient discoveryClient;
@RequestMapping("/service-instances/{applicationName}")
public List<ServiceInstance> serviceInstancesByApplicationName(
@PathVariable String applicationName) {
return this.discoveryClient.getInstances(applicationName);
}
@RequestMapping("/info")
public String sayhello() {
return "client-teacher";
}
// Restful服务对应的url地址
@Value("${rest.student.list}")
private String restStudentList;
@RequestMapping("/students")
public String test() {
// ServiceInstance instance = loadBalancer.choose("eureka-client-student");
// URI uri = instance.getUri();
List list = restTemplate.getForObject(restStudentList, List.class);
return list.toString();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
spring cloud netflix eureka ribbon 示例
共34个文件
prefs:9个
properties:7个
xml:5个
需积分: 10 17 下载量 182 浏览量
2017-03-03
18:35:17
上传
评论
收藏 26KB ZIP 举报
温馨提示
spring cloud netflix eureka ribbon 示例 服务注册发现调用
资源推荐
资源详情
资源评论
收起资源包目录
spring cloud netflix eureka ribbon demo.zip (34个子文件)
eureka-provider
.project 567B
src
test
resources
java
main
resources
application.properties 214B
java
com
yonyou
EurekaClientApplication.java 1KB
student
web
StudentController.java 1KB
Student.java 994B
.settings
org.eclipse.m2e.core.prefs 90B
org.eclipse.jdt.core.prefs 243B
org.eclipse.core.resources.prefs 191B
pom.xml 2KB
.classpath 1KB
eureka-consumer
.project 567B
src
test
resources
java
main
resources
application.properties 304B
java
com
yonyou
EurekaClientApplication.java 3KB
target
classes
application.properties 304B
META-INF
MANIFEST.MF 276B
maven
com.yonou
eureka-client
pom.properties 231B
pom.xml 2KB
test-classes
.settings
org.eclipse.m2e.core.prefs 90B
org.eclipse.jdt.core.prefs 736B
org.eclipse.core.resources.prefs 191B
pom.xml 2KB
.classpath 1KB
eureka-service
.project 566B
src
test
resources
java
main
resources
application.properties 298B
java
com
yonyou
EurekaServiceApplication.java 567B
target
classes
application.properties 298B
META-INF
MANIFEST.MF 278B
maven
com.yonyou
eureka-service
pom.properties 231B
pom.xml 2KB
test-classes
.settings
org.eclipse.m2e.core.prefs 90B
org.eclipse.jdt.core.prefs 736B
org.eclipse.core.resources.prefs 191B
pom.xml 2KB
.classpath 1KB
共 34 条
- 1
资源评论
泽佑兄弟
- 粉丝: 29
- 资源: 19
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 双H桥电机驱动L298N芯片AD集成库ALTIUM库(原理图库+PCB封装库)文件.zip
- 555springboot + vue 线上教学平台.zip(可运行源码+数据库文件+文档)
- 554springcloud + vue 房产销售平台.zip(可运行源码+数据库文件+文档)
- 小霸王坦克游戏源码.7z
- 蓝桥杯单片机基础学习项目(LED,数码管,蜂鸣器,继电器,按键控制)
- 553springboot + vue 某银行OA系统.zip(可运行源码+数据库文件+文档)
- DatabaseWatermarkingBasedonTextFormat
- yolov8常用二维码检测检测+数据集
- -移动通信-网络课程设计与研究
- 基于Python的PCA人脸识别算法的原理及实现代码+文档详解.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功