本文共 2975 字,大约阅读时间需要 9 分钟。
??????????????????????????????????????????????????????????????????????????????????
?????????????
Spring Cloud???????????????????????????
Eureka ?Spring Cloud??????????????????Eureka???????????????????????????????????
Zuul????????????????????????????????????????????????????????????
Ribbon?????????????????????????????????????????????????????????????????
Hystrix?????????????????????Hystrix???????????????????????????????????
org.springframework.cloud spring-cloud-starter-netflix-eureka-server
server: port: 8081eureka: instance: prefer-ip-address: true hostname: leo-node client: register-with-eureka: false fetch-registry: false service-url: defaultZone: http://${eureka.instance.hostname}:8082/eureka @SpringBootApplication@EnableEurekaServerpublic class EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class); }} ?IDE???????Eureka Server???????????????????????????????????Eureka??????????
org.springframework.cloud spring-cloud-starter-netflix-eureka-client
eureka: client: service-url: defaultZone: http://leo-node:8081/eureka register-with-eureka: true fetch-registry: trueserver: port: 8091
@SpringBootApplication@EnableEurekaClientpublic class ServiceProviderApplication { public static void main(String[] args) { SpringApplication.run(ServiceProviderApplication.class); }} org.springframework.cloud spring-cloud-starter-netflix-ribbon
eureka: client: service-url: defaultZone: http://leo-node:8081/eurekaserver: port: 9000
@Configurationpublic class RibbonConfig { @LoadBalanced @Bean public RestTemplate restTemplate() { return new RestTemplate(); }} @RestController@RequestMapping("/consumer/ribbon")public class ConsumerController { @Value("${server.port}") private String port; @Autowired private RestTemplate restTemplate; @RequestMapping("/sayHello") public String test() { return restTemplate.getForObject("http://service-provider-001/provider/sayHello", String.class); }} ????????????????????????
???????????????Spring Cloud??????????????????????????
转载地址:http://vyme.baihongyu.com/