简体   繁体   中英

Spring Cloud Config Server Could not resolve placeholder

I have added spring-cloud-config-server to my stack in the hope of having different sets of config loaded for different spring profiles (namely development, staging and production).

My config server app starts on port 8888, fetches config directly from a private gitlab repository and has security. I tested this by hitting it manually and checking that the correct properties are returning. So far so good.

I will have several 'client' apps that I want to consume the properties from my config server but for now I'm just trying with one. To test it out, I've put a

@Value("${some.property}")
private string someProperty;

in one of my web resources in the client app. This property is not in any of the client app's property files (wondering if this may be the issue - but it seems restrictive if it is).

I've also pointed the client app at the config server. The config for both apps both config server and client app are in their bootstrap.properties files to ensure they're loaded early in the process.

In fact my two apps are containerised in Docker images and they are brought up by a docker-compose.yml file. I've actually got it set up to that the client app waits for the config server to be running before starting up.

During the client app's startup, I can see it fetching config from the config server:

| 20:12:50.692 [main] INFO  o.s.c.c.c.ConfigServicePropertySourceLocator.getRemoteEnvironment 205 - Fetching config from server at : http://config-server:8888

and it appears to be successful with a 205.

However, the client app startup then fails:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'exampleResource': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'some.property' in value "${some.property}"

I have the active profile set to 'development' in the client app. The properties files on the config server are named:

myapp-development.properties
myapp-staging.properties
myapp-production.properties

My hope is of course that the client app fetches the config from the server (which I can see happen) and then that property is available to the client app as it starts up but this does not appear to be the case. Is it as simple as specifying a default in the value annotation? Or am I overlooking something more fundamental? I followed this guide fwiw and my config server is pointing to a git repository as I mentioned above:

http://www.baeldung.com/spring-cloud-configuration

Thanks in advance.

You set credentials incorrectly in the client side app.

It should be

spring.cloud.config.username=myConfigServerUserName
spring.cloud.config.password=myConfigServerPassword

instead of spring.security.user.name and spring.security.user.password (which are used in the config server app).

See: http://cloud.spring.io/spring-cloud-static/spring-cloud-config/2.0.1.RELEASE/single/spring-cloud-config.html#_security_2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM