提交 10ddc538 编写于 作者: 武汉红喜's avatar 武汉红喜

注解属性值引用properties

上级 d4e1bf4b
......@@ -7,7 +7,7 @@ import org.springframework.web.bind.annotation.RequestParam;
/**
* Created by shenhongxi on 2017/9/14.
*/
@FeignClient(value = "demo-provider", fallback = DemoHystrix.class)
@FeignClient(value = "${provider.name}", fallback = DemoHystrix.class)
public interface DemoFeign {
@RequestMapping("/hello")
String hello(@RequestParam(name = "name") String name); // 此处必须有RequestParam
......
......@@ -2,6 +2,7 @@ package org.hongxi.whatsmars.cloud.consumer.rpc;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
......@@ -13,10 +14,12 @@ public class DemoRpc {
@Autowired
private RestTemplate restTemplate;
@Autowired
private Environment env;
@HystrixCommand(fallbackMethod = "helloFallback")
public String hello(String name) {
return restTemplate.getForObject("http://demo-provider/hello?name=" + name, String.class);
return restTemplate.getForObject("http://" + env.getProperty("provider.name") + "/hello?name=" + name, String.class);
}
public String helloFallback(String name) {
......
......@@ -2,6 +2,9 @@ spring:
profiles:
active: dev
provider:
name: demo-provider
---
eureka:
client:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册