spring-cloud / spring-cloud/spring-cloud-config

Spring boot apps can't get properties from embedded config server

Open
#563 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

closable
Dominant language
Java
Stars
2k
Forks
1.3k
Avg merge
2d 59m
Merged PRs (30d)
16

Description

I use Spring cloud config 1.2.1
Java 1.8.92
And Windows OS

I try to embed spring cloud config in my spring boot application (spring cloud config server and other spring boot applications are part of the core), but it looks like my other applications, can't get properties from spring cloud.

Here the stacktrace, which I get when application start:

org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'hikariConfig' defined in class path resource [sample-application-context.xml]: Could not resolve placeholder 'user.password' in string value "${user.password}"; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'user.password' in string value "${user.password}"
	at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:223) 
	at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.processProperties(PropertySourcesPlaceholderConfigurer.java:180) 
	at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.postProcessBeanFactory(PropertySourcesPlaceholderConfigurer.java:152) 
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284) 
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:166)
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:681)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:523) 
	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) 
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) 
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) 
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) 
	at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:134) 
	at com.khrapavitski.embeddedconfig.common.ApplicationBuilder.lambda$build$0(ApplicationBuilder.java:71) [embeddedconfig/:na]
	at java.util.ArrayList.forEach(ArrayList.java:1249) 
	at com.khrapavitski.embeddedconfig.common.ApplicationBuilder.build(ApplicationBuilder.java:65) [embeddedconfig/:na]
	at Application.main(Application.java:25)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
	at java.lang.reflect.Method.invoke(Method.java:498) 
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) 

Here my boostrap.properties file:

spring.profiles.active=native
spring.cloud.config.server.bootstrap=true
spring.cloud.config.server.native.searchLocations=file:/embeddedconfig/properties

I try to get properties via postman and looks like config server works fine.

Also when I added this system property: System.setProperty(spring.cloud.config.name, child.appName) to application builder, application have worked fine.

Test project is here
embeddedconfig.zip

Thank you,
Raman

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the attached embeddedconfig.zip project and trace ApplicationBuilder at lines 65–71, then compare startup with and without the spring.cloud.config.name system property. Check the bootstrap.properties settings and the user.password placeholder failure. Done means embedded child applications load their config properties without requiring that workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.