spring-cloud / spring-cloud-config

External configuration (server and client) for Spring Cloud
Apache License 2.0
1.96k stars 1.29k forks source link

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

Open raman-khrapavitski opened 7 years ago

raman-khrapavitski commented 7 years ago

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

spencergibb commented 7 years ago

Are you trying to run multiple applications in one jvm, one of them being config server?

raman-khrapavitski commented 7 years ago

Yeah, that's right.

spencergibb commented 7 years ago

Config server wasn't built to support that model, so it doesn't surprise me that it doesn't work.

siarhei-usau commented 7 years ago

I have a question this case, what do see as "embedded config server" mode. Do you mean that embed configuration server into some spring boot application can't provide configuration to that application and provides configuration REST service only for other applications in network? Thx

Siarhei-Yarkavy commented 7 years ago

Hmm, it seems that is. Waiting for official comment.

spencergibb commented 7 years ago

It's meant to read configuration for a single application in embedded mode, not multiple.