Spring Cloud service name @FeignClient from properties file

I want to set service name to @FeignClient from properties file like:

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

      

and enter the name given in application.yml

, for example:

service.users: user-service

      

Where user-service

is the name by which the service is registered with Eureka.

I tried it and it doesn't work. He complains about an invalid name.

Can you do something like this?

+3
spring-cloud netflix-feign


source to share


3 answers


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



+1


source to share


This can be done as follows.

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



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

+1


source to share


I tried using a similar configuration:

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

      

application.yml, bootstrap.yml:

spring:
  application:
    name: my-test-application

      

checking the log after launch

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

      

Also I found in active zookeeper 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:

  • test your client bean at runtime with a hardcoded name (be sure to make sure it is created)
  • check scope for your config file (your variable from config file may not be available)
  • check your application.yml - I'm not sure if spring comunity has reserved the "service.users" variable name by default (you may need to add a custom dependency). Or, if you don't know the dependencies, but you need to use it,

create the following 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 there are problems with the additional spring-configuration-metadata.json you can find explanations here: enter link here

+1


source to share







All Articles