Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why spring client cannot obtain spring config server properties?

Tags:

spring

I've got a @SpringBootApplication, running with the production profile, and a spring config server,

{"name":"config-client","profiles":["production"],"label":null,"version":"97611975e6ddb87c7213e18ddbe203ab6ae5485d","state":null,"propertySources":[{"name":"http://git/scm/abm/abm-settings.git/application-production.yml","source":{"my.pretty.property.id":21}}]}

I cannot load property my.pretty.property.id from server (they are always null), I am using

@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "my.pretty.property")
public class MyProperties {
    private String id;
}

and my bootstrap.yml is

spring.cloud:
  config:
    uri: http://${SERVICE_HOST}/${PROJECT_KEY}-config-server
    enabled: false
    failFast: true

build.gradle contains this:

"org.springframework.cloud:spring-cloud-starter-consul-all",
"org.springframework.cloud:spring-cloud-consul-core",
"org.springframework.cloud:spring-cloud-starter-hystrix",
"org.springframework.cloud:spring-cloud-starter-hystrix-dashboard",
"org.springframework.cloud:spring-cloud-starter-zipkin",
"org.springframework.cloud:spring-cloud-config-client"

My client application is normally built and deployed, what am I missing?

like image 980
Bogdan Timofeev Avatar asked Oct 16 '22 06:10

Bogdan Timofeev


1 Answers

From Spring Cloud Config:

The HTTP service has resources in the form:

/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties

As you mentioned your application is running under production profile - hence Spring will try to find file: <cloud-config-server-url>/application-production.yml and load it, besides application.properties. But your properties are located in application-integration.yml and you don't use integration profile.

So the solution is to use an integration profile or to create an application-production.yml on your config. server.

like image 60
Vüsal Avatar answered Oct 20 '22 16:10

Vüsal