Reputation: 2913
I have two microservices demo-cartservice
and demo-feignclient
where the demo-feignclient
fetches resources from demo-cartservice
In both projects I set server.servlet.context-path=/demo/api/
in application.properties
The Feign client proxy uses the hardcoded server name for demo-cartservice
@FeignClient("demo-cartservice/demo/api")
@RibbonClient("demo-cartservice/demo/api")
public interface DemoCartServiceProxy
{
@GetMapping("/carts/{cartId}")
public Cart getCart(@PathVariable("cartId") long id);
}
This works fine.
Is there a way to read the server alias from application.properties
as well, like so:
@FeignClient("${cartservice-alias}/${servlet-context}")
@RibbonClient("${cartservice-alias}/${servlet-context}")
public interface DemoCartServiceProxy
{
@GetMapping("/carts/{cartId}")
public Cart getCart(@PathVariable("cartId") long id);
}
In application.properties
of the demo-feignclient
project I would like to have
server.servlet.context-path=/demo/api/
cartservice-alias=demo-cartservice
Thanks for the help
Upvotes: 0
Views: 1768
Reputation: 2913
Sorry should have checked the docs first. After setting
feign.name=demo-cartservice/demo/api
in application.properties
of demo-feignclient
this works:
@FeignClient(name="${feign.name}")
@RibbonClient(name="${feign.name}")
public interface DemoCartServiceProxy
{
@GetMapping("/carts/{cartId}")
public Cart getCart(@PathVariable("cartId") long id);
}
Upvotes: 1