I want to configure the spring beans in such a way that depending on the value of a boolean variable, one of the two available connection bean gets autowired in the code.
Below is the initialization of the boolean variable:
//This is overridden as false from the properties file on the server.
@Value(value = "${my.property.connectionOne:true}")
private boolean connectionOne;
I have defined the Bean in such a way:
@Bean(name = "specificConnection")
public Destination getSpecificConnection() throws Exception {
if (connectionOne) { //boolean variable
return new ConnectionOne("DB");
}
else {
return new ConnectionTwo("XML");
}
}
where ConnectionOne and ConnectionTwo both implement Destination
And I am using the bean in the desired class as:
@Autowired
@Qualifier(value = "specificConnection")
private Destination specificConnection;
However, it doesn't seem to work. It keeps returning ConnectionOne only even if I change the value of the boolean variable to false.
I am using Spring version 4.2.0 and Wildfly Server.
Please let me know if any further clarification is required.
@Value(value = "${my.property.connectionOne:true}") private boolean connectionOne;- phoenixSid