Open mfvanek opened 1 day ago
An additional special constructor for PgConnection? https://github.com/mfvanek/pg-index-health/blob/f1958cf4466217199885b3fe1ad427089842780e/pg-index-health-jdbc-connection/src/main/java/io/github/mfvanek/pg/connection/PgConnectionImpl.java#L63
Qualifier annotation cannot use SpEL. Only way to use context/beanFactory
@Bean
@ConditionalOnProperty(name = "custom.datasource.bean-name")
@ConditionalOnMissingBean
public PgConnection pgConnection(
@Value("${custom.datasource.bean-name:dataSource}") String dataSourceBeanName,
ConfigurableListableBeanFactory beanFactory,
@Value("${spring.datasource.url:#{null}}") String databaseUrl) {
DataSource dataSource = beanFactory.getBean(dataSourceBeanName, DataSource.class);
return PgConnectionImpl.ofUrl(dataSource, databaseUrl);
}
See https://github.com/mfvanek/pg-index-health/blob/006fd3db74fc677411c8843084aa8b3fac3ec6d7/spring-boot-integration/pg-index-health-test-starter/src/main/java/io/github/mfvanek/pg/spring/DatabaseStructureHealthAutoConfiguration.java#L59
In some projects bean might be customized very much
Need a way to do it without copying whole code for pgConnection bean