Oreste
Oreste

Reputation: 456

Spring Cloud @FeignClient service name from properties file

I want to set the service name in @FeignClient from a properties file, like this:

@FeignClient("${service.users}")

and have the name set in application.yml for example:

service.users: user-service

Where user-service is the name by which the service is registered in Eureka.

I have tried and it does not work. It complains for invalid name.

Can something like this be done?

Upvotes: 3

Views: 4111

Answers (3)

Serhii
Serhii

Reputation: 7543

i tried to use similar configuration:

@FeignClient(name = "${spring.application.name:optional.application.name}")

application.yml, bootstrap.yml:

spring:
  application:
    name: my-test-application

checking log after start

2016-05-24 16:11:00 [hystrix-my-test-application-1]                INFO  o.s.c.a.AnnotationConfigApplicationContext.prepareRefresh...

Also i had found in zookeeper active service

>ls /service/my-test-application 
[8668663c-cce1-4181-94de-4ccaacefa7e3]

checked in debug mode client bean - it was created

HardCodedTarget(type=EventBusClient, name=fnma-cp-test, url=http://my-test-application)

So this configuration should work. My suggestions are:

  1. check your client bean in runtime with hardcoded name (you need be sure that creates)
  2. check visibility scope for your config file (your variable from config file can be out of scope)
  3. check your application.yml - i do not sure, that spring comunity has reserved variable name 'service.users' by default (possible you need add special dependency). Or if you do not know dependency but needs use one,

please create next file structure:

 application.yml
 META-INF
 |-additional-spring-configuration-metadata.json

where additional-spring-configuration-metadata.json should have something like this

{
  "properties": [
    {
      "name": "service.users",
      "type": "java.lang.String",
      "description": "Description for service.users.",
      "defaultValue": "Some_Value"
    }
  ]
}

Anyway if any problems with additional-spring-configuration-metadata.json you can find explanations here: enter link description here

Upvotes: 1

cody123
cody123

Reputation: 2080

This can be done like this.

@FeignClient(name="fd-mobileapi-service",url="${fdmobile.ribbon.listOfServers}")

fdmobile.ribbon.listOfServers : value =>> this will be a property in application.properties.

Upvotes: 1

spencergibb
spencergibb

Reputation: 25147

It is an open issue. Pull requests are welcome :-)

Upvotes: 1

Related Questions