package com.yf.controller; import com.yf.service.OrderMemberService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.annotation.Order; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; /** * Created by 79782 on 2018/6/11. */ @RestController public class OrderMemberController { @Autowired private OrderMemberService orderMemberService; @RequestMapping("/orderGetService") public List<String> orderGetService(){ System.out.println("order use memeber...."); return orderMemberService.getOrderUserAll(); } }
package com.yf.service; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; import java.util.List; /** * Created by 79782 on 2018/6/11. */ @Service public class OrderMemberService { @Autowired private RestTemplate restTemplate; public List<String> getOrderUserAll(){ return restTemplate.getForObject("http://service-member/getMenberAll",List.class); } }
package com.yf; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.web.client.RestTemplate; /** * Created by 79782 on 2018/6/11. */ @ComponentScan(basePackages = { "com.yf" }) @SpringBootApplication @EnableEurekaClient public class EurekaApplication { public static void main(String[] args) { SpringApplication.run(EurekaApplication.class, args); } @Bean @LoadBalanced //支持负载均衡 RestTemplate restTemplate(){ return new RestTemplate(); } }
eureka: client: serviceUrl: defaultZone: http://localhost:8899/eureka/ server: port: 8764 spring: application: name: service-order