При попытке установить r2dbcCustomConversions я получаю исключительную ситуацию отображения "Не удалось найти PersistentEntity".
Я следовал некоторым фрагментам кода из справочных документов r2dbc
Вот мой код:
@Configuration
class ServiceConfiguration : AbstractR2dbcConfiguration() {
@Bean
override fun connectionFactory() =
ConnectionFactories.get("CONNECTION_STRING")
override fun r2dbcCustomConversions() = R2dbcCustomConversions(
storeConversions,
listOf(PersonReadConverter(), PersonWriteConverter())
)
}
@ReadingConverter
class PersonReadConverter : Converter<Row, Person> {
override fun convert(source: Row): Person {
return Person(
source.get("id", String::class.java),
source.get("name", String::class.java),
source.get("age", Int::class.java)
)
}
}
@WritingConverter
class PersonWriteConverter : Converter<Person, OutboundRow> {
override fun convert(source: Person): OutboundRow? {
val row = OutboundRow()
row["id"] = SettableValue.from(source.id!!)
row["name"] = SettableValue.from(source.name!!)
row["age"] = SettableValue.from(source.age!!)
return row
}
}
@Table
data class Person(@Id val id: String?, val name: String?, val age: Int?)
@Service
class PersonService(private val databaseClient: DatabaseClient) : InitializingBean {
override fun afterPropertiesSet() {
selectAll()
.subscribe(
{ println("Data: $it") },
{ println("Error: $it") },
{ println("Done") }
)
}
fun selectAll() = databaseClient
.select()
.from(Person::class.java)
.fetch()
.all()
}
Вот вывод, который я получаю:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personService' defined in file [\demo\reactive-web\target\classes\com\example\demo\PersonService.class]: Invocation of init method failed; nested exception is org.springframework.data.mapping.MappingException: Couldn't find PersistentEntity for type class com.example.demo.Person!
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1783) ~[spring-beans-5.2.0.M2.jar:5.2.0.M2]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.2.0.M2.jar:5.2.0.M2]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.2.0.M2.jar:5.2.0.M2]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.2.0.M2.jar:5.2.0.M2]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.0.M2.jar:5.2.0.M2]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.2.0.M2.jar:5.2.0.M2]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.2.0.M2.jar:5.2.0.M2]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:868) ~[spring-beans-5.2.0.M2.jar:5.2.0.M2]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.2.0.M2.jar:5.2.0.M2]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.2.0.M2.jar:5.2.0.M2]
at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:67) ~[spring-boot-2.2.0.M3.jar:2.2.0.M3]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:782) [spring-boot-2.2.0.M3.jar:2.2.0.M3]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:404) [spring-boot-2.2.0.M3.jar:2.2.0.M3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:319) [spring-boot-2.2.0.M3.jar:2.2.0.M3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1275) [spring-boot-2.2.0.M3.jar:2.2.0.M3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1263) [spring-boot-2.2.0.M3.jar:2.2.0.M3]
at com.example.demo.DemoApplicationKt.main(DemoApplication.kt:13) [classes/:na]
Я заметил, что документы немного устарели. Например, в примере PersonWriteConverter требуется использование SettableValue. Я не уверен, что это ошибка или я что-то упустил