I have a cloud config server running on localhost:8888 and a test app that uses properties from the config server, this uses the default uri localhost:8888. Now when I change the port to 8889 in both config server and client application using http://localhost:8889
as the spring.cloud.config.uri
value the client app does not start up and I get errors like.
Could not resolve placeholder 'some.property' in value "${some.property}"
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:372) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
Here is an extract of the build.gradle
buildscript {
ext {
springBootVersion = '1.5.9.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath('io.spring.gradle:dependency-management-plugin:0.5.4.RELEASE')
}
}
dependencies {
compile('org.springframework.cloud:spring-cloud-starter-config')
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-web')
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Edgware.RELEASE"
}
}
Also if I keep the config server uri as 8889 on the client but still start the config server at localhost:8888 everything works then even though it shouldn't really.
Have recorded a small vid of some debugging that might be useful
The gif starts from the yml file which shows that the port is 8889, afterwards the debug points placed get hit. As shown initially the first url value is having port 8888 (this is due to the default value assigned to the class variable). Next we show the console log which says
[ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at: http://localhost:8888
This seems to highlight that the default localhost:8888 url is used instead of 8889, then afterwards the setUri method gets hit with the correct port value 8889 however it seems too late as the exception above gets thrown later (not shown in the vid to keep it short and under 10MB though)
Comment From: spencergibb
The value needs to go in bootstrap.yml.
Comment From: mjosephd
Thanks a lot, that works! Will close out the issue as well.
Comment From: vmisra2018
HI Spencer, I have the property defined in bootstrap.yml for client dummy-service and config server is started at 8890 port
`
spring: application: name: dummy-service profiles: zone2 cloud: config: uri: http://localhost:8890 fail-fast: true profile: sit eureka: instance: instanceId: ${spring.cloud.client.hostname}:${spring.application.name}:${server.port} prefer-ip-address: true metadataMap: zone: zone1 client: serviceUrl: defaultZone: http://localhost:8761/eureka/ server: port: ${PORT:1100${SEQUENCE_NO}}
`
Still I see :
2020-02-10 16:21:37.428 INFO 84203 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2020-02-10 16:21:37.543 INFO 84203 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Connect Timeout Exception on Url - http://localhost:8888. Will be trying the next url if available
2020-02-10 16:21:37.544 WARN 84203 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/application/default": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
And next in controller I am trying to get profiled value I am getting error org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.dummyServiceController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.profiles' in value "${spring.profiles}"
Comment From: spencergibb
Without a project that reproduces the problem, I won't be able to help
Comment From: vmisra2018
Hi Spencer, This looks like springboot 2.2.4.RELEASE issue when we pass multiple arguments. Apparently they have changed the way to pass arguments
https://github.com/spring-projects/spring-boot/issues/20115