spring boot 啟動類 添加組件
阿新 • • 發佈:2018-03-12
urn back members size RR highlight class sleep ndk
@SpringBootApplication @EnableEurekaClient @EnableCircuitBreaker @ServletComponentScan public class SaleApp { @Bean @LoadBalanced public RestTemplate getRestTemplate() { return new RestTemplate(); } public static void main(String[] args) { new SpringApplicationBuilder(SaleApp.class).web(true).run(args); } }
@Service //@DefaultProperties(defaultFallback = "getMemberFallback") public class MemberService { @Autowired private RestTemplate restTpl; @HystrixCommand(fallbackMethod = "getMemberFallback", groupKey = "MemberGroup", commandKey = "MemberCommandKey", commandProperties = { @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1000") }, threadPoolProperties = { @HystrixProperty(name = "coreSize", value = "2") }) public Member getMember(Integer id) { try { Thread.sleep(2000); } catch (Exception e) { } Member member = restTpl.getForObject( "http://spring-hy-member/member/{id}", Member.class, id); return member; } public Member getMemberFallback(Integer id) { Member m = new Member(); m.setId(1); m.setName("error member"); return m; } }
spring boot 啟動類 添加組件