I have a configuration class in my spring boot application which I want to enable only if certain properties in my application.properties
file matches it.
@Configuration
@ConditionalOnProperty(prefix = "^sites\\[.*\\].*", name = "^prefix.*")
public class TestConfiguration {
@Bean
@Primary
public TestManager getTestManager() {
System.out.println("Created TestManager"); //just for debugging purposes
return new TestManager();
}
}
In my application.properties
file I have a set of properties as below:
sites[0].id=site1
sites[0].name=site1 name
sites[0].datasource.url=
sites[0].datasource.user=
sites[1].id=site2
sites[1].name=site2 name
sites[1].datasource.url=
sites[1].datasource.user=
.
.
site[n].... so on
I want to create my TestManager
bean only if these properties are present. When I try to have regex pattern on my prefix attribute it's not working out. What is the correct way of handling such situations? Is there any better approach for this problem?