I have two different configuration which i would be loading from application yml. The properties are same but the values might differ.
How do i make this work giveMeRestTemplate(Type config)
// app.yml
bus:
tyres:8
seats:40
color:red
url: www.businfo.com
car:
tyres:4
seats:6
color:blue
url: www.carinfo.com
So i have different ConfigruationProperties class for this like below one other as CarConfig
@ConfigurationProperties("bus")
public class BusConfig{
public int tyres;
public int seats;
public string color ;
public string url;
//setters and getters below.
}
Then i have a rest client which i use to invoke some api to fetch information. So this api can return information of different types of vehicles you can say.
public class RestClientHelper{
public RestTemplate giveMeRestTemplate(Type config);
{
return restTemplate; //using the above type which might have url to the specific api to call.
}
}
The idea is that the calling code can get different rest templates based on what config was sent to it.
public SomeClient{
@Autowired
RestClientHelper rch;
@Autowired
BusConfig bc;
@Autowired
CarConfig cc;
public void publishDetails(){
rch.giveMeRestTemplate(bc); //so if i send cc then it should prepare rest template for cc
}
}