question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Name R2dbcEntityTemplate explicitly

See original GitHub issue

I believe this isn’t fully supported yet but attempting to use r2dbc DSL with repositories, pretty close but I believe it wants the R2dbcEntityTemplate bean named “r2dbcEntityTemplate” explicitly:

https://github.com/spring-projects/spring-data-r2dbc/blob/1.2.x/src/main/java/org/springframework/data/r2dbc/repository/config/EnableR2dbcRepositories.java#L139

19:31:29.421 [restartedMain] WARN  o.s.b.w.r.c.AnnotationConfigReactiveWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contractLifecycleRepository' defined in com.xxx.ContractLifecycleRepository defined in @EnableR2dbcRepositories declared on R2dbcRepositoriesAutoConfigureRegistrar.EnableR2dbcRepositoriesConfiguration: Cannot resolve reference to bean 'r2dbcEntityTemplate' while setting bean property 'entityOperations'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'r2dbcEntityTemplate' available

When creating the beans manually in lieu of using r2dbc DSL I run into the same problem and it’s resolved by naming it explicitly:

        bean<R2dbcEntityTemplate>("r2dbcEntityTemplate") {
            ref<R2dbcDataAutoConfiguration>().r2dbcEntityTemplate(ref())
        }

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
fteychenecommented, Dec 14, 2020

After testing the naming is required indeed.

@sdeleuze What do you think about naming the R2dbcEntityTemplate created by dataR2dbc since it seems that other parts depends on it by bean naming convention ?

In the mean time this configuration seems to be working With this configuration the application boot :

fun databaseConfiguration(databaseConfig: DatabaseConfig): ConfigurationDsl {
        return configuration {
            r2dbc {
                url = databaseConfig.url
                transactional = true // creates transactional operator
                optionsCustomizers = connectionFactoryOptionsCustomizers(databaseConfig)
                username = databaseConfig.username
                password = databaseConfig.password
            }
            beans {
                bean("r2dbcEntityTemplate") { R2dbcEntityTemplate(ref<ConnectionFactory>()) }
            }
        }
    }
1reaction
peterfigurecommented, Dec 14, 2020

when I use my forked spring-fu:

~/develop/spring-fu-fork  ‹peterfigure/add_buildinfo_dsl*› $ git diff
diff --git a/autoconfigure-adapter/src/main/java/org/springframework/boot/autoconfigure/data/r2dbc/R2dbcDataInitializer.java b/autoconfigure-adapter/src/main/java/org/springframework/boot/autoconfigure/data/r2dbc/R2dbcDataInitializer.java
index 650a05ea..6e310069 100644
--- a/autoconfigure-adapter/src/main/java/org/springframework/boot/autoconfigure/data/r2dbc/R2dbcDataInitializer.java
+++ b/autoconfigure-adapter/src/main/java/org/springframework/boot/autoconfigure/data/r2dbc/R2dbcDataInitializer.java
@@ -47,7 +47,7 @@ public class R2dbcDataInitializer implements ApplicationContextInitializer<Gener
             }
         };
 
-        context.registerBean(R2dbcEntityTemplate.class, () -> r2dbcDataConfiguration.get().r2dbcEntityTemplate(context.getBean(R2dbcConverter.class)));
+        context.registerBean("r2dbcEntityTemplate", R2dbcEntityTemplate.class, () -> r2dbcDataConfiguration.get().r2dbcEntityTemplate(context.getBean(R2dbcConverter.class)));
         context.registerBean(R2dbcCustomConversions.class, () -> r2dbcDataConfiguration.get().r2dbcCustomConversions());
         context.registerBean(R2dbcMappingContext.class, () -> r2dbcDataConfiguration.get().r2dbcMappingContext(context.getBeanProvider(NamingStrategy.class), context.getBean(R2dbcCustomConversions.class)));
         context.registerBean(MappingR2dbcConverter.class, () -> r2dbcDataConfiguration.get().r2dbcConverter(context.getBean(R2dbcMappingContext.class), context.getBean(R2dbcCustomConversions.class)));

it works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Data R2DBC - Reference Documentation
The version name follows ${calver} for GA releases and service releases and the ... so this repository clearly belongs to Spring Data JPA....
Read more >
spring-projects/spring-data - Gitter
I have a @ManyToOne relationship between CarModel and EngineType in my code. I have written a native query to fetch the data since...
Read more >
java - How do I handle nullable fields using either the Mono ...
R2DBC and Spring Data R2DBC make null handling explicit by requiring either binding a value to your Statement or binding a null ....
Read more >
Spring Data R2DBC CRUD Example - Vinsguru
Here we clearly assume that for any new product, id would be null to ... R2dbcEntityTemplate.lambda$update$5(R2dbcEntityTemplate.java:402) ...
Read more >
Spring Data R2DBC [PostgreSQL] - Medium
As inferred from its name, it's an implementation of ... Basically using a R2dbcEntityTemplate, queries would be delegated to DatabaseClient discussed ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found