使用最新的Micronaut 3.4.1micronaut数据和MongoDB。继续将异常获取为java.lang.NoClassDefFoundError: org/bson/internal/CodecRegistryHelper
渐变相关性
dependencies {
annotationProcessor("io.micronaut.data:micronaut-data-document-processor:3.3.0")
implementation 'org.mongodb:bson:4.5.1'
implementation("io.micronaut.data:micronaut-data-mongodb:3.3.0")
implementation 'io.micronaut.mongodb:micronaut-mongo-reactive:4.1.0'
implementation 'io.micronaut.reactor:micronaut-reactor:2.2.2'
implementation "io.micronaut:micronaut-inject:3.4.1"
annotationProcessor "io.micronaut:micronaut-inject-java:3.4.1"
annotationProcessor "io.micronaut:micronaut-validation:3.4.1"
implementation 'io.micronaut:micronaut-validation:3.4.1'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
implementation("fete.bird:common:1.0-SNAPSHOT")
}
存储库
@MongoRepository
public interface IOrderRepository extends ReactorCrudRepository<Order, ObjectId> {
}
服务
@Singleton
public record OrderService(IOrderRepository iOrderRepository) implements IOrderService {
@Override
public Mono<Order> create(Order model) {
return iOrderRepository.save(model).map(item -> {
return new Order(item.getId(), item.getOrderName(), item.getOrderBy());
});
}
}
实体
@MappedEntity
public class Order {
@Id
@GeneratedValue
private ObjectId id;
private String OrderName;
private String OrderBy;
public Order(ObjectId id, String orderName, String orderBy) {
this.id = id;
OrderName = orderName;
OrderBy = orderBy;
}
public Order() {
}
// Getter and setter
}
异常
Message: org/bson/internal/CodecRegistryHelper
Path Taken: MongoRepositoryOperations.syncOperations(DefaultReactiveMongoRepositoryOperations reactiveOperations) --> MongoRepositoryOperations.syncOperations([DefaultReactiveMongoRepositoryOperations reactiveOperations]) --> new DefaultReactiveMongoRepositoryOperations(String serverName,BeanContext beanContext,List codecs,DateTimeProvider dateTimeProvider,RuntimeEntityRegistry runtimeEntityRegistry,DataConversionService conversionService,AttributeConverterRegistry attributeConverterRegistry,[MongoClient mongoClient])
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:2363)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1128)
at io.micronaut.context.DefaultBeanContext$6.create(DefaultBeanContext.java:2906)
at io.micronaut.runtime.context.scope.refresh.RefreshScope.lambda$getOrCreate$0(RefreshScope.java:102)
at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708)
at io.micronaut.runtime.context.scope.refresh.RefreshScope.getOrCreate(RefreshScope.java:101)
at io.micronaut.context.DefaultBeanContext.getScopedBeanForDefinition(DefaultBeanContext.java:2889)
at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:2822)
at io.micronaut.context.DefaultBeanContext.getProxyTargetBean(DefaultBeanContext.java:1423)
at io.micronaut.configuration.mongo.reactive.$DefaultReactiveMongoClientFactory$MongoClient0$Definition$Intercepted.interceptedTarget(Unknown Source)
at io.micronaut.configuration.mongo.reactive.$DefaultReactiveMongoClientFactory$MongoClient0$Definition$Intercepted.startSession(Unknown Source)
at io.micronaut.data.mongodb.operations.DefaultReactiveMongoRepositoryOperations.lambda$withClientSession$25(DefaultReactiveMongoRepositoryOperations.java:713)
at reactor.core.publisher.MonoDeferContextual.subscribe(MonoDeferContextual.java:47)
at reactor.core.publisher.Mono.subscribe(Mono.java:4400)
at reactor.core.publisher.Mono.block(Mono.java:1706)
at fete.bird.aggregate.command.CreateOrderCommand$CreateOrderCommandHandler.handler(CreateOrderCommand.java:20)
at fete.bird.aggregate.command.CreateOrderCommand$CreateOrderCommandHandler.handler(CreateOrderCommand.java:13)
at fete.bird.utils.ServiceBus.send(ServiceBus.java:27)
at fete.bird.OrderController.post(OrderController.java:36)
at fete.bird.$OrderController$Definition$Intercepted.$$access$$post(Unknown Source)
at fete.bird.$OrderController$Definition$Exec.dispatch(Unknown Source)
at io.micronaut.context.AbstractExecutableMethodsDefinition$DispatchedExecutableMethod.invoke(AbstractExecutableMethodsDefinition.java:378)
at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:128)
at io.micronaut.validation.ValidatingInterceptor.intercept(ValidatingInterceptor.java:138)
at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:137)
at fete.bird.$OrderController$Definition$Intercepted.post(Unknown Source)
at fete.bird.$OrderController$Definition$Exec.dispatch(Unknown Source)
at io.micronaut.context.AbstractExecutableMethodsDefinition$DispatchedExecutableMethod.invoke(AbstractExecutableMethodsDefinition.java:378)
at io.micronaut.context.DefaultBeanContext$4.invoke(DefaultBeanContext.java:583)
at io.micronaut.web.router.AbstractRouteMatch.execute(AbstractRouteMatch.java:303)
at io.micronaut.web.router.RouteMatch.execute(RouteMatch.java:111)
at io.micronaut.http.context.ServerRequestContext.with(ServerRequestContext.java:103)
at io.micronaut.http.server.RouteExecutor.lambda$executeRoute$14(RouteExecutor.java:659)
at reactor.core.publisher.FluxDeferContextual.subscribe(FluxDeferContextual.java:49)
at reactor.core.publisher.Flux.subscribe(Flux.java:8469)
at reactor.core.publisher.FluxFlatMap$FlatMapMain.onNext(FluxFlatMap.java:426)
at io.micronaut.reactive.reactor.instrument.ReactorSubscriber.onNext(ReactorSubscriber.java:57)
at reactor.core.publisher.MonoCreate$DefaultMonoSink.success(MonoCreate.java:165)
at io.micronaut.http.server.netty.RoutingInBoundHandler$4.doOnComplete(RoutingInBoundHandler.java:939)
at io.micronaut.core.async.subscriber.CompletionAwareSubscriber.onComplete(CompletionAwareSubscriber.java:79)
at io.micronaut.http.server.netty.jackson.JsonContentProcessor$1.doOnComplete(JsonContentProcessor.java:136)
at io.micronaut.core.async.subscriber.CompletionAwareSubscriber.onComplete(CompletionAwareSubscriber.java:79)
at java.base/java.util.Optional.ifPresent(Optional.java:178)
at io.micronaut.core.async.processor.SingleThreadedBufferingProcessor.doOnComplete(SingleThreadedBufferingProcessor.java:48)
at io.micronaut.jackson.core.parser.JacksonCoreProcessor.doOnComplete(JacksonCoreProcessor.java:94)
at io.micronaut.core.async.subscriber.SingleThreadedBufferingSubscriber.onComplete(SingleThreadedBufferingSubscriber.java:71)
at io.micronaut.http.server.netty.jackson.JsonContentProcessor.doOnComplete(JsonContentProcessor.java:161)
at io.micronaut.core.async.subscriber.CompletionAwareSubscriber.onComplete(CompletionAwareSubscriber.java:79)
at io.micronaut.http.netty.reactive.HandlerPublisher.publishMessage(HandlerPublisher.java:383)
at io.micronaut.http.netty.reactive.HandlerPublisher.flushBuffer(HandlerPublisher.java:470)
at io.micronaut.http.netty.reactive.HandlerPublisher.publishMessageLater(HandlerPublisher.java:360)
at io.micronaut.http.netty.reactive.HandlerPublisher.complete(HandlerPublisher.java:423)
at io.micronaut.http.netty.reactive.HandlerPublisher.handlerRemoved(HandlerPublisher.java:418)
at io.netty.channel.AbstractChannelHandlerContext.callHandlerRemoved(AbstractChannelHandlerContext.java:946)
at io.netty.channel.DefaultChannelPipeline.callHandlerRemoved0(DefaultChannelPipeline.java:637)
at io.netty.channel.DefaultChannelPipeline.remove(DefaultChannelPipeline.java:477)
at io.netty.channel.DefaultChannelPipeline.remove(DefaultChannelPipeline.java:423)
at io.micronaut.http.netty.stream.HttpStreamsHandler.removeHandlerIfActive(HttpStreamsHandler.java:483)
at io.micronaut.http.netty.stream.HttpStreamsHandler.handleReadHttpContent(HttpStreamsHandler.java:319)
at io.micronaut.http.netty.stream.HttpStreamsHandler.channelRead(HttpStreamsHandler.java:282)
at io.micronaut.http.netty.stream.HttpStreamsServerHandler.channelRead(HttpStreamsServerHandler.java:134)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93)
at io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtensionHandler.channelRead(WebSocketServerExtensionHandler.java:99)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93)
at io.netty.handler.codec.http.HttpServerKeepAliveHandler.channelRead(HttpServerKeepAliveHandler.java:64)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.handler.flow.FlowControlHandler.dequeue(FlowControlHandler.java:200)
at io.netty.handler.flow.FlowControlHandler.read(FlowControlHandler.java:139)
at io.netty.channel.AbstractChannelHandlerContext.invokeRead(AbstractChannelHandlerContext.java:686)
at io.netty.channel.AbstractChannelHandlerContext.read(AbstractChannelHandlerContext.java:671)
at io.micronaut.http.netty.reactive.HandlerPublisher.requestDemand(HandlerPublisher.java:165)
at io.micronaut.http.netty.stream.HttpStreamsHandler$2.requestDemand(HttpStreamsHandler.java:273)
at io.micronaut.http.netty.reactive.HandlerPublisher$ChannelSubscription.receivedDemand(HandlerPublisher.java:556)
at io.micronaut.http.netty.reactive.HandlerPublisher$ChannelSubscription.lambda$request$0(HandlerPublisher.java:494)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:469)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:833)
Suppressed: java.lang.Exception: #block terminated with an error
at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:99)
at reactor.core.publisher.Mono.block(Mono.java:1707)
... 83 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/bson/internal/CodecRegistryHelper
at com.mongodb.reactivestreams.client.internal.MongoClientImpl.<init>(MongoClientImpl.java:95)
at com.mongodb.reactivestreams.client.internal.MongoClientImpl.<init>(MongoClientImpl.java:72)
at com.mongodb.reactivestreams.client.MongoClients.createMongoClient(MongoClients.java:136)
at com.mongodb.reactivestreams.client.MongoClients.createWithAsynchronousSocketChannel(MongoClients.java:170)
at com.mongodb.reactivestreams.client.MongoClients.create(MongoClients.java:114)
at com.mongodb.reactivestreams.client.MongoClients.create(MongoClients.java:96)
at io.micronaut.configuration.mongo.reactive.DefaultReactiveMongoClientFactory.mongoClient(DefaultReactiveMongoClientFactory.java:48)
at io.micronaut.configuration.mongo.reactive.$DefaultReactiveMongoClientFactory$MongoClient0$Definition.build(Unknown Source)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:2336)
... 97 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.bson.internal.CodecRegistryHelper
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 106 common frames omitted
18:41:04.731 [cluster-rtt-ClusterId{value='62495da056c2316f65d63381', description='null'}-localhost:27017] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:2, serverValue:1280}] to localhost:27017
18:41:04.731 [cluster-ClusterId{value='62495da056c2316f65d63381', description='null'}-localhost:27017] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:1, serverValue:1279}] to localhost:27017
18:41:04.731 [cluster-ClusterId{value='62495da056c2316f65d63381', description='null'}-localhost:27017] INFO org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=13, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=21954417}
Application.yml
mongodb:
uri: "mongodb://${MONGO_HOST:localhost}:${MONGO_PORT:27017}/FeteBird-Product"
示例-https://github.com/anandjaisy/Micronaut-Data-MongoDB
您缺少一个MongoDB驱动程序。