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

Spring boot starter r2dbc - configuration bug #21586

Closed
ndopj opened this issue May 26, 2020 · 9 comments
Closed

Spring boot starter r2dbc - configuration bug #21586

ndopj opened this issue May 26, 2020 · 9 comments
Labels
for: external-project For an external project and not something we can fix

Comments

@ndopj
Copy link

ndopj commented May 26, 2020

Current release 2.3.0 contains a bug when using auto-configuration and manual configuration of r2dbc drivers to use reactive repositories, making reactive repositories functionality unusable at all.

Gradle Dependencies:

    dependencyManagement {
        imports {
            mavenBom("org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE")
        }
    }

    dependencies {
         implementation('org.springframework.boot:spring-boot-starter-data-r2dbc:2.3.0.RELEASE')
         implementation('io.r2dbc:r2dbc-h2')
         implementation('io.r2dbc:r2dbc-pool')
    }

application.properties

spring.r2dbc.url=r2dbc:h2://localhost/test
spring.r2dbc.username=sa
spring.r2dbc.password=password
spring.r2dbc.initialization-mode=always

Spring Boot main application:

@SpringBootApplication
@EnableR2dbcRepositories(basePackages = {"com.**"})
public class ApplicationLauncher {
    public static void main(String[] args) {
        SpringApplication.run(ApplicationLauncher.class, args);
    }
}

Error:

Description:

Field accountRepository in com.**.DatabaseAccountService required a bean named 'r2dbcDatabaseClient' that could not be found.

When trying to do configuration manually different error occures (same dependencies but without application.properties r2dbc properties):

Configuration

@Configuration
@EnableTransactionManagement
@PropertySource(value = "classpath:application.properties")
@EnableR2dbcRepositories(basePackages = {"com.**"})
public class CoreR2dbcConfiguration extends AbstractR2dbcConfiguration {

    @Override
    @Bean
    public ConnectionFactory connectionFactory() {
        H2ConnectionConfiguration configuration = H2ConnectionConfiguration.builder()
                .inMemory("testDB")
                .username("sa")
                .password("password")
                .build();
        return new H2ConnectionFactory(configuration);
    }

    @Bean
    ReactiveTransactionManager transactionManager(ConnectionFactory connectionFactory) {
        return new R2dbcTransactionManager(connectionFactory);
    }
}

Error:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.springframework.data.r2dbc.mapping.R2dbcMappingContext.<init>(R2dbcMappingContext.java:45)

The following method did not exist:

    'void org.springframework.data.r2dbc.mapping.R2dbcMappingContext.setForceQuote(boolean)'

This is probably somehow linked to:
spring-projects/spring-data-r2dbc#296 (comment)
Mentioned conflict reason is usage of wrong dependencies, but since i am only using spring boot starter dependencies this is not my case.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 26, 2020
@philwebb
Copy link
Member

@ndopj Are you able to share a sample project to save us a bit of time building one from the snippets you provided?

@philwebb philwebb added the status: waiting-for-feedback We need additional information before we can continue label May 26, 2020
@ndopj
Copy link
Author

ndopj commented May 27, 2020

https://github.com/ndopj/spring-boot-2.3.0-r2dbc-bug/tree/manual-configuration-bug

Master branch contains configuration for the first specified case. The second case is really probably conflict between (as was proposed within issue linked in the description) spring-boot-data-jpa and spring-boot-data-r2dbc dependencies, since i am using both of them in my project. However i am still not able to reproduce second case bug in regular project so i will investigate further on my own.
Edit:
spring-data-relational is used by both spring-data-r2dbc, spring-data-jdbc:
https://mvnrepository.com/artifact/org.springframework.data/spring-data-relational/usages

That means following conflict reason might be causing second case bug (since i am getting exactly same error), if spring-boot-starter-data-jdbc and spring-boot-starter-data-r2dbc are using different version of spring-data-relational:
spring-projects/spring-data-r2dbc#296 (comment)

For the first bug, possible solution might be creation of bean r2dbcDatabaseClient manually, but i would expect spring boot auto-configuration to configure that bean same as EntityManager bean is configured in case of spring-boot-starter-data-jpa, with use of properties inside application.properties file, so one can use "CrudRepositories" without any additional configuration.

Both bugs i mentioned are already mentioned in the link i posted in the description of this issue:
spring-projects/spring-data-r2dbc#296,

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels May 27, 2020
@snicoll
Copy link
Member

snicoll commented May 27, 2020

@ndopj thanks for the sample but this project works fine for me (if we ignore the r2dbc url that I've changed to use an in-memory database. Just to confirm, I am using the branch). The error you've described above could happen if you use the experimental r2dbc support that has moved to Spring Boot 2.3 or if your dependency management is broken. None of that is the case in the sample that you've shared and it works properly for me.

To go further with this, we need a sample that reproduces the error above.

@snicoll snicoll added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels May 27, 2020
@ndopj
Copy link
Author

ndopj commented May 27, 2020

With clearing gradle cache, project cache, gradle dependencies and reevaluating the project i can confirm that auto-configuration in the first case is working properly as expected. I need to investigate second case on my own since as @snicoll proposed, problems might have different origin as i tough and i am not able to reproduce. I am using only spring boot 2.3.0 starter dependencies.

Thank you all for cooperation and sorry for time taken by this issue, since it doesn't seem to be bug at all.

@ndopj ndopj closed this as completed May 27, 2020
@snicoll
Copy link
Member

snicoll commented May 27, 2020

Thanks for letting us know.

@snicoll snicoll added status: invalid An issue that we don't feel is valid and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels May 27, 2020
@ndopj
Copy link
Author

ndopj commented May 27, 2020

After hours of debugging dependencies in gradle i've finally found out that second case error might occur when using spring-boot-starter-data-r2dbc together with spring-cloud-sleuth dependency management. I am using latest version of spring-cloud-sleuth (2.2.2.RELEASE: Mar, 2020). Note that gradle automatically downgrades most of spring boot starter dependencies to 2.2.5 versions with this dependency management setup.

    dependencyManagement {
        imports {
            mavenBom("org.springframework.boot:spring-boot-dependencies:2.3.0.RELEASE")
            mavenBom("org.springframework.cloud:spring-cloud-sleuth:2.2.2.RELEASE")
        }
    }

@philwebb
Copy link
Member

@ndopj I'm having trouble replicating that behavior, can you please share a sample project that shows the downgrades happening?

@philwebb philwebb reopened this May 28, 2020
@philwebb philwebb added status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged and removed status: invalid An issue that we don't feel is valid labels May 28, 2020
@wilkinsona
Copy link
Member

This looks like a mistake in the Spring Cloud Sleuth documentation to me. It recommends using spring-cloud-sleuth as a bom but it doesn't look like it should be used that way to me. Via its parent it pulls in spring-boot-dependencies which results in it potentially clobbering your Spring Boot version. At a glance, spring-cloud-sleuth-dependencies or spring-cloud-dependencies (the latter is what start.spring.io recommends) look like better alternatives to me.

@snicoll
Copy link
Member

snicoll commented May 28, 2020

It is indeed and the reference guide actually describes the correct setup. I've created spring-cloud/spring-cloud-sleuth#1658 so that this page refers to the correct bom.

@ndopj you can also create an app on start.spring.io with the dependencies that your project needs if you want an example of a working setup.

@snicoll snicoll closed this as completed May 28, 2020
@snicoll snicoll added for: external-project For an external project and not something we can fix and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels May 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix
Projects
None yet
Development

No branches or pull requests

5 participants