I am new to Spring Cloud and I am trying to connect a server and client, using a property file stored on github.
My server application.yml file is configured as follows:
---
server:
port: 8888
spring:
cloud:
config:
server:
git:
uri: https://github.com/JonEasy/pluralsight-spring-cloudconfig-wa-tolls.git
#username: uname
#password: pass
search-paths:
- 'station*'
repos:
perf:
pattern:
- '*/perf'
uri: https://github.com/JonEasy/pluralsight-spring-cloudconfig-wa-tolls-perf.git
search-paths:
- 'station*'
The github repos are linked here Main Properties and Alternative Properties
My client application has the following setup
spring.application.name=s1rates
spring.profiles.active=default
spring.cloud.config.uri=http://localhost:8888
spring.cloud.config.enabled= true
And the Rest Controller is :
@Controller
public class RateController {
@Value("${rate}")
String rate;
@Value("${lanecount}")
String lanecount;
@Value("${tollstart}")
String tollstart;
@RequestMapping("/rate")
public String getRate(Model m) {
m.addAttribute("rateamount", rate);
m.addAttribute("lanes", lanecount);
m.addAttribute("tollstart", tollstart);
//name of the view
return "rateview";
}
}
All the ${variables} van be found inside the properties file located in the git repositories.
The server is executing fine but the Client is giving me the following error
Error creating bean with name 'rateController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'rate' in value "${rate}"
Also note that my spring application name "s1rates" is matching the properties files inside my main repository under station1/s1rates.properties.
Any hint?
I was facing the same issue and found this post helpful.
However I will consolidate my findings here.
Make sure your spring cloud client has correct pom.xml file.
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>2020.0.0</version>
</parent>
and add dependency
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
Rest all properties given in multiple posts, are generally fine.
For example in client bootstrap.properties file
spring.application.name=s1rates
spring.profiles.active=default
spring.cloud.config.uri=http://localhost:8888
spring.cloud.config.enabled= true