【发布时间】:2020-01-24 08:40:51
【问题描述】:
我想使用 @FeignClient 根据运行的环境从属性中获取 URL。
赞:我有test、dev 和prod。所有这些环境对于 example 都有不同的 URL:
test:http://localhost:9000
dev:http://localhost:8080
prod : http://localhost:8181
@FeignClient(name = "my-test-servies", url = "${com.test.my.access.url}")
@RequestMapping(method = RequestMethod.GET, value = "/authors")
public interface MyFeignClient {
public List<Author> getAuthors();
}
这可行,但我希望根据环境更改 URL 属性。当我使用单个属性文件时,我的 yml 属性文件如下:application.yml
com:
prod:
my:
access:
url: "http://localhost:8181"
test:
my:
access:
url: "http://localhost:9000"
dev:
my:
access:
url: "http://localhost:8080"
可以吗?如果可以;怎么样?
【问题讨论】:
-
使用配置文件并删除属性中对 env 的显式调用?
-
配置文件仅用于此目的。您希望在单个文件中拥有所有属性的任何具体原因?
-
是的,我在我的其他服务中使用配置文件,但我想在我的服务中使用单个 yml/property 文件。
标签: java spring spring-boot openfeign