Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataSourceBuilder throws an UnsupportedDataSourcePropertyException when trying to derive a DataSource from an unknown DataSource type #27295

Closed
ghost opened this issue Jul 12, 2021 · 3 comments
Assignees
Labels
status: reserved-for-conference-event status: superseded An issue that has been superseded by another type: bug A general bug

Comments

@ghost
Copy link

ghost commented Jul 12, 2021

In our application (Spring Boot 2.5.2) we are trying to use com.amazonaws.xray.sql.TracingDataSource as the primary DataSource; it's essentially a wrapper around a regular data source to enable AWS X-Ray metrics.
During startup, the application tries to create a derived DataSource from it (DataSourceBuilder.derivedFrom(dataSource), the Liquibase starter is doing this).
The TracingDataSource is not recognized as a source for MappedDataSourceProperties, so we end up with a ReflectionDataSourceProperties, trying to to find the getters for the properties by reflection. However, it is erroneously looking for getter methods with one String parameter (DataSourceProperty:293-294). Even if such getters were to exist, they are later on (ReflectionDataSourceProperties:553) called with no parameters, resulting in an IllegalArgumentException anyway.

Example configuration to trigger the issue:

  @Bean(name = "dataSource")
  @Primary
  public DataSource tracingDataSource(HikariDataSource dataSource) {
    return new TracingDataSource(dataSource) {
      public String getUrl() {
        return ((HikariDataSource) delegate).getJdbcUrl();
      }
      ...
    };
  }

  @Bean
  public HikariDataSource hikariDataSource(DataSourceProperties properties) {
    HikariDataSource dataSource =
        properties.initializeDataSourceBuilder().type(HikariDataSource.class).build();
    if (StringUtils.hasText(properties.getName())) {
      dataSource.setPoolName(properties.getName());
    }
    return dataSource;
  }

  @Bean
  public DataSource derived(@Qualifier("dataSource") DataSource dataSource) {
    DataSourceBuilder<?> builder =
        DataSourceBuilder.derivedFrom(dataSource).type(SimpleDriverDataSource.class);
    return builder.build(); // UnsupportedDataSourcePropertyException: Unable to find suitable method for url
  }
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 12, 2021
@wilkinsona wilkinsona changed the title ReflectionDataSourceProperties is unusable DataSourceBuilder throws an UnsupportedDataSourcePropertyException when trying to derive a DataSource from an unknown DataSource type Jul 12, 2021
@wilkinsona wilkinsona added this to the 2.5.x milestone Jul 12, 2021
@wilkinsona wilkinsona added type: bug A general bug status: reserved-for-conference-event and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 12, 2021
@wilkinsona
Copy link
Member

wilkinsona commented Jul 12, 2021

Thanks for the report, @migueldiogo-cycleon. While you're waiting for a fix, I think you could work around the problem by using @LiquibaseDataSource on a @Bean method that defines the Liquibase-specific DataSource rather than setting spring.liquibase.user and .password.

@ghost
Copy link
Author

ghost commented Jul 13, 2021

@wilkinsona thanks for the workaround! I managed to get things working with the @LiquibaseDataSource annotation as you suggested.
If I can be of further assistance in solving this issue, please let me know.

saraswathy-krish added a commit to saraswathy-krish/spring-boot that referenced this issue Jul 22, 2021
…datasource type

This fix eliminates the unsupported datasource property exception thrown when trying to derive a datasource from an unknown datasource type  by calling ReflectionUtils on the getters and setters of the unknown datasource type.

Fixes spring-projects#27295
@wilkinsona
Copy link
Member

Closing in favor of #27453.

@wilkinsona wilkinsona removed this from the 2.5.x milestone Jul 22, 2021
@wilkinsona wilkinsona added the status: superseded An issue that has been superseded by another label Jul 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: reserved-for-conference-event status: superseded An issue that has been superseded by another type: bug A general bug
Projects
None yet
3 participants