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 ConsumerApp {
/**
* 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(ConsumerApp.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;
@Value("${server.port}")
private String port;
@RequestMapping("/students")
public String test() {
// ServiceInstance instance = loadBalancer.choose("eureka-client-student");
// URI uri = instance.getUri();
List list = restTemplate.getForObject(restStudentList, List.class);
return port+" : "+list.toString();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
spring cloud eureka zuul ribbon hystrix feign config 示例 (154个子文件)
UserController.class 2KB
ServiceInstanceRestController.class 2KB
UserController.class 2KB
ConsumerApp.class 1KB
StudentController.class 1KB
Student.class 1KB
ServiceInstanceRestController.class 1KB
UserService.class 1KB
ConfigServerApp.class 963B
TestController.class 949B
User.class 939B
User.class 929B
FeignClientApp.class 893B
FeignServerApp.class 893B
ConfigTestApp.class 890B
EurekaServerApp.class 767B
ProviderApp.class 753B
ZuulApp.class 731B
HomeController.class 674B
.classpath 1KB
.classpath 1KB
.classpath 1KB
.classpath 1KB
.classpath 1KB
.classpath 1KB
.classpath 1KB
.classpath 1KB
feign-client-0.0.1-SNAPSHOT.jar 35.8MB
ConsumerApp.java 3KB
ProviderApp.java 1KB
StudentController.java 1KB
UserController.java 1KB
UserController.java 1KB
UserService.java 1KB
Student.java 994B
User.java 618B
User.java 613B
FeignClientApp.java 591B
TestController.java 588B
EurekaServerApp.java 549B
ConfigServerApp.java 534B
FeignServerApp.java 509B
ConfigTestApp.java 441B
HomeController.java 425B
ZuulApp.java 410B
inputFiles.lst 256B
createdFiles.lst 103B
inputFiles.lst 0B
MANIFEST.MF 279B
MANIFEST.MF 279B
MANIFEST.MF 277B
MANIFEST.MF 277B
MANIFEST.MF 276B
MANIFEST.MF 276B
MANIFEST.MF 275B
MANIFEST.MF 268B
feign-client-0.0.1-SNAPSHOT.jar.original 4KB
org.eclipse.core.resources.prefs 250B
org.eclipse.core.resources.prefs 250B
org.eclipse.core.resources.prefs 250B
org.eclipse.core.resources.prefs 248B
org.eclipse.jdt.core.prefs 243B
org.eclipse.jdt.core.prefs 243B
org.eclipse.jdt.core.prefs 243B
org.eclipse.jdt.core.prefs 243B
org.eclipse.jdt.core.prefs 243B
org.eclipse.jdt.core.prefs 243B
org.eclipse.jdt.core.prefs 243B
org.eclipse.jdt.core.prefs 243B
org.eclipse.core.resources.prefs 191B
org.eclipse.core.resources.prefs 191B
org.eclipse.core.resources.prefs 191B
org.eclipse.core.resources.prefs 191B
org.eclipse.m2e.core.prefs 90B
org.eclipse.m2e.core.prefs 90B
org.eclipse.m2e.core.prefs 90B
org.eclipse.m2e.core.prefs 90B
org.eclipse.m2e.core.prefs 90B
org.eclipse.m2e.core.prefs 90B
org.eclipse.m2e.core.prefs 90B
org.eclipse.m2e.core.prefs 90B
org.eclipse.m2e.core.prefs 90B
org.eclipse.m2e.core.prefs 90B
org.eclipse.m2e.core.prefs 90B
org.eclipse.m2e.core.prefs 90B
org.eclipse.core.resources.prefs 57B
org.eclipse.core.resources.prefs 57B
org.eclipse.core.resources.prefs 57B
org.eclipse.core.resources.prefs 57B
.project 567B
.project 567B
.project 565B
.project 565B
.project 564B
.project 564B
.project 563B
.project 556B
.project 386B
.project 386B
.project 385B
共 154 条
- 1
- 2
资源评论
- liuzuowei0072018-03-22没啥用,哪都能搜到,没必要用这么多分下这个
- 石头_llahn2017-09-01写的一般吧,提供了点思路
- habibi642017-12-07资源和博客内容不匹配,不建议下载
泽佑兄弟
- 粉丝: 29
- 资源: 19
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功