I have two classes/beans annotated with @Configuration and I have to instantiate
based on the value from the property file.
@Configuration
public class RemoteServer1 {
//some authentication logic goes here
}
@Configuration
public class RemoteServer2 {
//some authentication logic goes here
}
remote.server.location=RemoteServer1
Now i want to instantiate @Configuration class/bean matched with value from property file.
I would suggest you look into the @Contidional... annotations in Spring Boot to conditionally activate Beans, Configurations etc.
http://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/autoconfigure/condition/ConditionalOnProperty.html
This should work looking at the property and config. For the first configuration,
@ConditionalOnProperty(name="remote.server.location", havingValue="RemoteServer1", matchIfMissing=false)
Second,
@ConditionalOnProperty(name="remote.server.location", havingValue="RemoteServer2", matchIfMissing=false)
Looks for the property name, matches on havingValue, will not evaluate to true if the property is missing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With