Question
Hi,
I am trying to override the findOne method of JdbcEnvironmentRepository class. Is there any way to achieve this by using existing jdbc profile and only override the above mentioned method?
Please help in this. any sample code will help to do this. Note: I am able to configure a custom profile and execute my own multiple sql queries. but I want to achieve this using spring cloud provided jdbc profile.
Comment From: ryanjbaxter
Can you provide a sample of what you have tried that didn't work?
Comment From: hpss0145
Hi Ryan,
Below is the code changes I am trying to customize the org.springframework.cloud.config.server.environment.JdbcEnvironmentRepository#findOne method inside JdbcEnvironmentRepository class. Link to the code : GitRepoLink In the above linked code, I am trying to override the JdbcEnvironmentRepository's findOne method and JdbcEnvironmentRepositoryFactory's build method to get CustomJdbcEnvironmentRepository's findOne method which I created to customize. Please correct me If I am doing anything wrong here. as I am getting below error: "Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed"
Please suggest me any sample code or correct way of doing it. Thanks in advance.
Comment From: ryanjbaxter
Try changing CustomEnvironmentRepositoryConfiguration to this
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(JdbcTemplate.class)
@ConditionalOnProperty(value = "spring.cloud.config.server.jdbc.enabled", matchIfMissing = true)
@AutoConfigureAfter(JdbcTemplateAutoConfiguration.class)
@AutoConfigureBefore(EnvironmentRepositoryConfiguration.class)
public class CustomEnvironmentRepositoryConfiguration{
@Bean
@Primary
@ConditionalOnBean(JdbcTemplate.class)
public JdbcEnvironmentRepositoryFactory customJdbcEnvironmentRepositoryFactory(JdbcTemplate jdbc) {
return new CustomJdbcEnvironmentRepositoryFactory(jdbc);
}
}
Comment From: hpss0145
@ryanjbaxter, It worked. Now I am able to call the customJdbcRepository implementation. Thank you so much for the quick response.