Open muazhari opened 2 years ago
Do you have the init line in your main ?
LcReactiveDataRelationalInitializer.init();
Yes, I have. Below is the application class.
package com.sg.atlas;
import net.lecousin.reactive.data.relational.LcReactiveDataRelationalInitializer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
@SpringBootApplication
@ConfigurationPropertiesScan("com.sg.atlas.infrastructure.property")
public class AtlasServiceApplication {
public static void main(String[] args) {
LcReactiveDataRelationalInitializer.init();
SpringApplication.run(AtlasServiceApplication.class, args);
}
}
This is the startup console log from the app run. It gives information that the lc-spring-data-r2dbc found 7 entity classes but when the repository method is called, why the lc-spring-data-r2dbc can't recognise it?
Connected to the target VM, address: '127.0.0.1:51515', transport: 'socket'
11:30:08.567 [main] INFO net.lecousin.reactive.data.relational.LcReactiveDataRelationalInitializer - Initializing lc-reactive-data-relational
11:30:08.577 [main] INFO net.lecousin.reactive.data.relational.LcReactiveDataRelationalInitializer - No entities declared in lc-reactive-data-relational.yaml => scan class path
11:30:12.096 [main] INFO net.lecousin.reactive.data.relational.enhance.ClassPathScanningEntities - 7 entity classes found in 3518 ms.
11:30:12.103 [main] INFO net.lecousin.reactive.data.relational.enhance.Enhancer - Enhancing 7 entity classe(s)
11:30:12.231 [Thread-0] DEBUG org.springframework.boot.devtools.restart.classloader.RestartClassLoader - Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader@7267fafd
Below is the repository.
package com.sg.atlas.infrastructure.repository;
import com.sg.atlas.infrastructure.model.entity.Account;
import net.lecousin.reactive.data.relational.repository.LcR2dbcRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface AccountRepository extends LcR2dbcRepository<Account, Long> {
}
It may come from the Spring devtools restart feature, can you try to disable it and check if it works without it ?
Wait for me to disable it.
New error after disabling spring dev tools dependency.
2022-05-07 13:24:58.609 ERROR 19300 --- [actor-tcp-nio-2] r.n.channel.ChannelOperationsHandler : [9b43bc54, L:/[0:0:0:0:0:0:0:1]:61405 - R:localhost/[0:0:0:0:0:0:0:1]:5432] Error was received while reading the incoming data. The connection will be closed.
java.lang.NoClassDefFoundError: Could not initialize class io.r2dbc.postgresql.codec.StringCodec
at io.r2dbc.postgresql.codec.DefaultCodecs.getDefaultCodecs(DefaultCodecs.java:88) ~[r2dbc-postgresql-0.9.1.RELEASE.jar:0.9.1.RELEASE]
at io.r2dbc.postgresql.codec.DefaultCodecs.<init>(DefaultCodecs.java:81) ~[r2dbc-postgresql-0.9.1.RELEASE.jar:0.9.1.RELEASE]
at io.r2dbc.postgresql.codec.DefaultCodecs.<init>(DefaultCodecs.java:66) ~[r2dbc-postgresql-0.9.1.RELEASE.jar:0.9.1.RELEASE]
at io.r2dbc.postgresql.PostgresqlConnectionFactory.lambda$doCreateConnection$13(PostgresqlConnectionFactory.java:157) ~[r2dbc-postgresql-0.9.1.RELEASE.jar:0.9.1.RELEASE]
at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:125) ~[reactor-core-3.4.17.jar:3.4.17]
at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onNext(FluxOnErrorResume.java:79) ~[reactor-core-3.4.17.jar:3.4.17]
at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onNext(FluxOnErrorResume.java:79) ~[reactor-core-3.4.17.jar:3.4.17]
at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:120) ~[reactor-core-3.4.17.jar:3.4.17]
at reactor.core.publisher.MonoDelayUntil$DelayUntilCoordinator.complete(MonoDelayUntil.java:418) ~[reactor-core-3.4.17.jar:3.4.17]
at reactor.core.publisher.MonoDelayUntil$DelayUntilTrigger.onComplete(MonoDelayUntil.java:531) ~[reactor-core-3.4.17.jar:3.4.17]
at reactor.core.publisher.FluxHandle$HandleSubscriber.onComplete(FluxHandle.java:220) ~[reactor-core-3.4.17.jar:3.4.17]
at reactor.core.publisher.FluxHandle$HandleConditionalSubscriber.onComplete(FluxHandle.java:437) ~[reactor-core-3.4.17.jar:3.4.17]
at reactor.core.publisher.FluxCreate$BaseSink.complete(FluxCreate.java:460) ~[reactor-core-3.4.17.jar:3.4.17]
at reactor.core.publisher.FluxCreate$BufferAsyncSink.drain(FluxCreate.java:805) ~[reactor-core-3.4.17.jar:3.4.17]
at reactor.core.publisher.FluxCreate$BufferAsyncSink.complete(FluxCreate.java:753) ~[reactor-core-3.4.17.jar:3.4.17]
at reactor.core.publisher.FluxCreate$SerializedFluxSink.drainLoop(FluxCreate.java:247) ~[reactor-core-3.4.17.jar:3.4.17]
at reactor.core.publisher.FluxCreate$SerializedFluxSink.drain(FluxCreate.java:213) ~[reactor-core-3.4.17.jar:3.4.17]
at reactor.core.publisher.FluxCreate$SerializedFluxSink.complete(FluxCreate.java:204) ~[reactor-core-3.4.17.jar:3.4.17]
at io.r2dbc.postgresql.client.ReactorNettyClient$Conversation.complete(ReactorNettyClient.java:619) ~[r2dbc-postgresql-0.9.1.RELEASE.jar:0.9.1.RELEASE]
at io.r2dbc.postgresql.client.ReactorNettyClient$BackendMessageSubscriber.emit(ReactorNettyClient.java:885) ~[r2dbc-postgresql-0.9.1.RELEASE.jar:0.9.1.RELEASE]
at io.r2dbc.postgresql.client.ReactorNettyClient$BackendMessageSubscriber.onNext(ReactorNettyClient.java:761) ~[r2dbc-postgresql-0.9.1.RELEASE.jar:0.9.1.RELEASE]
at io.r2dbc.postgresql.client.ReactorNettyClient$BackendMessageSubscriber.onNext(ReactorNettyClient.java:667) ~[r2dbc-postgresql-0.9.1.RELEASE.jar:0.9.1.RELEASE]
at reactor.core.publisher.FluxHandle$HandleSubscriber.onNext(FluxHandle.java:126) ~[reactor-core-3.4.17.jar:3.4.17]
at reactor.core.publisher.FluxPeekFuseable$PeekConditionalSubscriber.onNext(FluxPeekFuseable.java:854) ~[reactor-core-3.4.17.jar:3.4.17]
at reactor.core.publisher.FluxMap$MapConditionalSubscriber.onNext(FluxMap.java:220) ~[reactor-core-3.4.17.jar:3.4.17]
at reactor.core.publisher.FluxMap$MapConditionalSubscriber.onNext(FluxMap.java:220) ~[reactor-core-3.4.17.jar:3.4.17]
at reactor.netty.channel.FluxReceive.drainReceiver(FluxReceive.java:279) ~[reactor-netty-core-1.0.18.jar:1.0.18]
at reactor.netty.channel.FluxReceive.onInboundNext(FluxReceive.java:388) ~[reactor-netty-core-1.0.18.jar:1.0.18]
at reactor.netty.channel.ChannelOperations.onInboundNext(ChannelOperations.java:404) ~[reactor-netty-core-1.0.18.jar:1.0.18]
at reactor.netty.channel.ChannelOperationsHandler.channelRead(ChannelOperationsHandler.java:93) ~[reactor-netty-core-1.0.18.jar:1.0.18]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.76.Final.jar:4.1.76.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.76.Final.jar:4.1.76.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-transport-4.1.76.Final.jar:4.1.76.Final]
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:327) ~[netty-codec-4.1.76.Final.jar:4.1.76.Final]
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:299) ~[netty-codec-4.1.76.Final.jar:4.1.76.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.76.Final.jar:4.1.76.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.76.Final.jar:4.1.76.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-transport-4.1.76.Final.jar:4.1.76.Final]
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) ~[netty-transport-4.1.76.Final.jar:4.1.76.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.76.Final.jar:4.1.76.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.76.Final.jar:4.1.76.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) ~[netty-transport-4.1.76.Final.jar:4.1.76.Final]
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166) ~[netty-transport-4.1.76.Final.jar:4.1.76.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:722) ~[netty-transport-4.1.76.Final.jar:4.1.76.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:658) ~[netty-transport-4.1.76.Final.jar:4.1.76.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:584) ~[netty-transport-4.1.76.Final.jar:4.1.76.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496) ~[netty-transport-4.1.76.Final.jar:4.1.76.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986) ~[netty-common-4.1.76.Final.jar:4.1.76.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.76.Final.jar:4.1.76.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.76.Final.jar:4.1.76.Final]
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.NoClassDefFoundError: io/r2dbc/spi/Type [in thread "reactor-tcp-nio-1"]
at java.base/java.lang.ClassLoader.defineClass1(Native Method) ~[na:na]
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1013) ~[na:na]
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150) ~[na:na]
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862) ~[na:na]
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760) ~[na:na]
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681) ~[na:na]
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ~[na:na]
at io.r2dbc.postgresql.codec.StringCodec.<clinit>(StringCodec.java:48) ~[r2dbc-postgresql-0.9.1.RELEASE.jar:0.9.1.RELEASE]
... 51 common frames omitted
Looks like a dependency version conflict, can you try to put the dependency io.r2dbc:r2dbc-spi:0.9.1.RELEASE at the top of your dependencies ? For maven:
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-spi</artifactId>
<version>0.9.1.RELEASE</version>
</dependency>
ok, the error is fixed now. how do you know the problem is dependency conflict? and, why classloaders from spring dev tools could make this lc-spring-data-r2dbc dependency not work as normal?
I will fix the version conflict by adding the version in the dependency management, because currently spring data depends on the previous r2dbc-spi version (0.8) while we already upgraded our drivers to the latest 0.9.1.RELEASE.
Regarding the spring devtools, it does not work because lc-spring-data-r2dbc needs to enhance entity classes at startup, but the devtools reload the original class in a different ClassLoader. I will have a look how we can support it.
Thanks for the explanation! I hope the new fixes and features got contributed :D
The new release 0.10.1 should fix the 2 issues. Could you try to upgrade and tell if it fixes it for your case ?
Already upgraded to 0.10.1 but still need to specify implementation 'io.r2dbc:r2dbc-spi:0.9.1.RELEASE'
and runtimeOnly 'io.r2dbc:r2dbc-postgresql:0.9.1.RELEASE'
in build.gradle dependencies. And, the classloader problem from spring devtools is fixed now.
net.lecousin.reactive.data.relational.model.ModelAccessException: Unknown entity type
I have that error even though I already annotated the entity class with
@Table(value="table_name")
and entity class property with@Column(value="column_name")
to be recognized as entity. Why the entity is didn't recognized by lc-spring-data-r2dbc? Can anyone help me to solve this problem? Thanks in advance!Below is the entity.
Below is the complete stack trace.