所以
我的Quarkus项目(v2.2.2)具有以下核心功能:
在编写测试时,我在夸克斯启动过程中遇到了一个错误(忘记了那个错误是什么),但是一些页面建议交换到指定的数据源来避免这个问题。当时这似乎已经奏效,我的模拟存储库测试通过了。
快进一点,我试着做一个使用数据库的测试。我现在得到这个错误:
java.lang.NullPointerException: Cannot invoke "org.hibernate.reactive.mutiny.Mutiny$Session.createQuery(String)" because "em" is null
at io.quarkus.hibernate.reactive.panache.common.runtime.CommonPanacheQueryImpl.createBaseQuery(CommonPanacheQueryImpl.java:307)
at io.quarkus.hibernate.reactive.panache.common.runtime.CommonPanacheQueryImpl.createQuery(CommonPanacheQueryImpl.java:255)
at io.quarkus.hibernate.reactive.panache.common.runtime.CommonPanacheQueryImpl.lambda$list$6(CommonPanacheQueryImpl.java:221)
at io.smallrye.context.impl.wrappers.SlowContextualFunction.apply(SlowContextualFunction.java:21)
at io.smallrye.mutiny.operators.uni.UniOnItemTransformToUni$UniOnItemTransformToUniProcessor.performInnerSubscription(UniOnItemTransformToUni.java:68)
at io.smallrye.mutiny.operators.uni.UniOnItemTransformToUni$UniOnItemTransformToUniProcessor.onItem(UniOnItemTransformToUni.java:57)
我的申请。yml(指定数据源为客户
):
quarkus:
datasource:
customers:
db-kind: h2
jdbc: false
reactive:
url: h2:file:~/testdb
max-size: 20
我的测试:
@QuarkusTest
public class CustomerControllerTest {
private static final String BASE_URL = "/my-url";
@Test
public void testBasicCreation() {
final Response response = given()
.when()
.body("{\"a\":3}")
.post(BASE_URL)
.then()
.extract().response();
assertEquals(200, response.getStatusCode(), () -> "Got: " + response.prettyPrint());
assertEquals("", response.getBody().as(String.class));
}
}
我的控制器的第一步是使用此存储库:
@ApplicationScoped
public class MyCustRepo implements io.quarkus.hibernate.reactive.panache.PanacheRepository<MyCust> {
}
我的实体:
@Entity(name = "cust_entries")
@Data
@PersistenceUnit("customers")
public class MyCust {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;
@Column(name = "val")
Boolean val;
}
据我所知,实体对象上的@persistenceUnit
应该与相应的数据源相关联。然而,Mutiny$Session似乎为空。我错过什么了吗?
更新1
关于Quarkusv 2.3.0 CR1
<properties>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<lombok-mapstruct-binding.version>0.2.0</lombok-mapstruct-binding.version>
<maven.compiler.parameters>true</maven.compiler.parameters>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<org.mapstruct.version>1.5.0.Beta1</org.mapstruct.version>
<org.projectlombok.version>1.18.20</org.projectlombok.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>2.3.0.CR1</quarkus.platform.version>
<surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
</properties>
完整的依赖树:https://www.codepile.net/pile/8jQeJ3j2
场景1:默认数据源(没有PersistenceUnit注释和application.yaml没有数据源的名称)
在运行测试我得到这个错误:
java.lang.RuntimeException: java.lang.RuntimeException: Failed to start quarkus
Caused by: java.lang.RuntimeException: Failed to start quarkus
Caused by: java.lang.RuntimeException: javax.persistence.PersistenceException: Unable to build EntityManagerFactory
Caused by: javax.persistence.PersistenceException: Unable to build EntityManagerFactory
Caused by: java.lang.IllegalStateException: No pool has been defined for persistence unit default-reactive
场景2:如果我将其设置为使用命名的数据源,我会得到:
my.project.customer.conrtoller.CustomerControllerTest.testBasicCreation Time elapsed: 2.12 s <<< FAILURE!
org.opentest4j.AssertionFailedError:
Got: {
"details": "Error id 083dd288-ddff-463b-bfd1-dafdbbf13c98-1, java.lang.NullPointerException: Cannot invoke \"org.hibernate.reactive.mutiny.Mutiny$Session.createQuery(String)\" because \"em\" is null",
"stack": "java.lang.NullPointerException: Cannot invoke \"org.hibernate.reactive.mutiny.Mutiny$Session.createQuery(String)\" because \"em\" is null\r\n\tat io.quarkus.hibernate.reactive.panache.common.runtime.CommonPanacheQueryImpl.createBaseQuery(CommonPanacheQueryImpl.java:307)\r\n\tat io.quarkus.hibernate.reactive.panache.common.runtime.CommonPanacheQueryImpl.createQuery(CommonPanacheQueryImpl.java:255)\r\n\tat io.quarkus.hibernate.reactive.panache.common.runtime.CommonPanacheQueryImpl.lambda$list$6(CommonPanacheQueryImpl.java:221)\r\n\tat io.smallrye.context.impl.wrappers.SlowContextualFunction.apply(SlowContextualFunction.java:21)\r\n\tat io.smallrye.mutiny.operators.uni.UniOnItemTransformToUni$UniOnItemTransformToUniProcessor.performInnerSubscription(UniOnItemTransformToUni.java:68)\r\n\tat io.smallrye.mutiny.operators.uni.UniOnItemTransformToUni$UniOnItemTransformToUniProcessor.onItem(UniOnItemTransformToUni.java:57)\r\n\tat io.smallrye.mutiny.operators.uni.builders.UniCreateFromKnownItem$KnownItemSubscription.forward(UniCreateFromKnownItem.java:38)\r\n\tat io.smallrye.mutiny.operators.uni.builders.UniCreateFromKnownItem$KnownItemSubscription.access$100(UniCreateFromKnownItem.java:26)\r\n\tat io.smallrye.mutiny.operators.uni.builders.UniCreateFromKnownItem.subscribe(UniCreateFromKnownItem.java:23)\r\n\tat io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:36)\r\n\tat io.smallrye.mutiny.operators.uni.UniOnItemTransformToUni.subscribe(UniOnItemTransformToUni.java:25)\r\n\tat io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:36)\r\n\tat io.smallrye.mutiny.converters.uni.UniToMultiPublisher$UniToMultiSubscription.request(UniToMultiPublisher.java:58)\r\n\tat io.smallrye.mutiny.operators.multi.MultiFlatMapOp$FlatMapMainSubscriber.onSubscribe(MultiFlatMapOp.java:163)\r\n\tat io.smallrye.mutiny.converters.uni.UniToMultiPublisher.subscribe(UniToMultiPublisher.java:26)\r\n\tat io.smallrye.mutiny.groups.MultiCreate$1.subscribe(MultiCreate.java:156)\r\n\tat io.smallrye.mutiny.operators.multi.MultiFlatMapOp.subscribe(MultiFlatMapOp.java:56)\r\n\tat io.smallrye.mutiny.groups.MultiSubscribe.withSubscriber(MultiSubscribe.java:69)\r\n\tat io.smallrye.mutiny.operators.multi.MultiSelectWhereOp.subscribe(MultiSelectWhereOp.java:30)\r\n\tat io.smallrye.mutiny.operators.AbstractMulti.subscribe(AbstractMulti.java:40)\r\n\tat io.smallrye.mutiny.operators.multi.MultiFlatMapOp.subscribe(MultiFlatMapOp.java:56)\r\n\tat io.smallrye.mutiny.operators.AbstractMulti.subscribe(AbstractMulti.java:40)\r\n\tat io.smallrye.mutiny.operators.uni.builders.UniCreateFromPublisher$PublisherSubscriber.forward(UniCreateFromPublisher.java:42)\r\n\tat io.smallrye.mutiny.operators.uni.builders.UniCreateFromPublisher$PublisherSubscriber.access$100(UniCreateFromPublisher.java:30)\r\n\tat io.smallrye.mutiny.operators.uni.builders.UniCreateFromPublisher.subscribe(UniCreateFromPublisher.java:26)\r\n\tat io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:36)\r\n\tat io.smallrye.mutiny.operators.uni.UniOnItemTransform.subscribe(UniOnItemTransform.java:22)\r\n\tat io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:36)\r\n\tat io.smallrye.mutiny.operators.uni.UniOnItemTransform.subscribe(UniOnItemTransform.java:22)\r\n\tat io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:36)\r\n\tat io.smallrye.mutiny.operators.uni.UniOnItemTransformToUni.subscribe(UniOnItemTransformToUni.java:25)\r\n\tat io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:36)\r\n\tat io.smallrye.mutiny.operators.uni.UniOnItemTransform.subscribe(UniOnItemTransform.java:22)\r\n\tat io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:36)\r\n\tat io.smallrye.mutiny.operators.uni.UniOnItemTransform.subscribe(UniOnItemTransform.java:22)\r\n\tat io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:36)\r\n\tat io.smallrye.mutiny.groups.UniSubscribe.withSubscriber(UniSubscribe.java:50)\r\n\tat io.smallrye.mutiny.groups.UniSubscribe.with(UniSubscribe.java:90)\r\n\tat org.jboss.resteasy.reactive.server.handlers.UniResponseHandler.handle(UniResponseHandler.java:17)\r\n\tat org.jboss.resteasy.reactive.server.handlers.UniResponseHandler.handle(UniResponseHandler.java:8)\r\n\tat org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:141)\r\n\tat io.vertx.core.impl.EventLoopContext.execute(EventLoopContext.java:81)\r\n\tat io.vertx.core.impl.ContextImpl.execute(ContextImpl.java:260)\r\n\tat io.vertx.core.impl.EventLoopContext.execute(EventLoopContext.java:22)\r\n\tat org.jboss.resteasy.reactive.server.vertx.VertxResteasyReactiveRequestContext$1.execute(VertxResteasyReactiveRequestContext.java:69)\r\n\tat org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.resume(AbstractResteasyReactiveContext.java:82)\r\n\tat org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.resume(AbstractResteasyReactiveContext.java:50)\r\n\tat org.jboss.resteasy.reactive.server.handlers.InputHandler$InputListener.done(InputHandler.java:84)\r\n\tat org.jboss.resteasy.reactive.server.vertx.VertxResteasyReactiveRequestContext$5.handle(VertxResteasyReactiveRequestContext.java:260)\r\n\tat org.jboss.resteasy.reactive.server.vertx.VertxResteasyReactiveRequestContext$5.handle(VertxResteasyReactiveRequestContext.java:254)\r\n\tat io.vertx.core.impl.AbstractContext.dispatch(AbstractContext.java:100)\r\n\tat io.vertx.core.impl.AbstractContext.dispatch(AbstractContext.java:63)\r\n\tat io.vertx.core.http.impl.HttpEventHandler.handleEnd(HttpEventHandler.java:76)\r\n\tat io.vertx.core.http.impl.Http1xServerRequest.onEnd(Http1xServerRequest.java:565)\r\n\tat io.vertx.core.http.impl.Http1xServerRequest.lambda$pendingQueue$1(Http1xServerRequest.java:127)\r\n\tat io.vertx.core.streams.impl.InboundBuffer.handleEvent(InboundBuffer.java:240)\r\n\tat io.vertx.core.streams.impl.InboundBuffer.write(InboundBuffer.java:130)\r\n\tat io.vertx.core.http.impl.Http1xServerRequest.handleEnd(Http1xServerRequest.java:546)\r\n\tat io.vertx.core.impl.EventLoopContext.execute(EventLoopContext.java:71)\r\n\tat io.vertx.core.impl.DuplicatedContext.execute(DuplicatedContext.java:163)\r\n\tat io.vertx.core.http.impl.Http1xServerConnection.onEnd(Http1xServerConnection.java:189)\r\n\tat io.vertx.core.http.impl.Http1xServerConnection.onContent(Http1xServerConnection.java:179)\r\n\tat io.vertx.core.http.impl.Http1xServerConnection.handleOther(Http1xServerConnection.java:159)\r\n\tat io.vertx.core.http.impl.Http1xServerConnection.handleMessage(Http1xServerConnection.java:147)\r\n\tat io.vertx.core.net.impl.ConnectionBase.read(ConnectionBase.java:155)\r\n\tat io.vertx.core.net.impl.VertxHandler.channelRead(VertxHandler.java:154)\r\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)\r\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)\r\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)\r\n\tat io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93)\r\n\tat io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtensionHandler.channelRead(WebSocketServerExtensionHandler.java:99)\r\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)\r\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)\r\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)\r\n\tat io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)\r\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)\r\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)\r\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)\r\n\tat io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)\r\n\tat io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)\r\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)\r\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)\r\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)\r\n\tat io.vertx.core.http.impl.Http1xOrH2CHandler.end(Http1xOrH2CHandler.java:61)\r\n\tat io.vertx.core.http.impl.Http1xOrH2CHandler.channelRead(Http1xOrH2CHandler.java:38)\r\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)\r\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)\r\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)\r\n\tat io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)\r\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)\r\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)\r\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)\r\n\tat io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)\r\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)\r\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)\r\n\tat io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)\r\n\tat io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)\r\n\tat io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)\r\n\tat io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)\r\n\tat io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)\r\n\tat io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)\r\n\tat io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)\r\n\tat io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)\r\n\tat io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)\r\n\tat java.base/java.lang.Thread.run(Thread.java:832)"
} ==> expected: <200> but was: <500>
at my.project.customer.conrtoller.CustomerControllerTest.testBasicCreation(CustomerControllerTest.java:35)
在撰写本答案时,使用夸克是不可能的。这里已经打开了一个功能请求:https://github.com/quarkusio/quarkus/issues/20471
我有一个有两个数据源的项目,一个主数据源和一个备用数据源。我已将这些添加到应用程序中。属性,我正在使用数据库多租户方法。我有一个定制的TenantResolver实现,可以更改活动租户,我定义的唯一实体是在外部模块中。 问题很简单:保存到我的两个数据源工作正常,但是为了启动应用程序,我必须包含一个虚拟数据源: 在属性文件中。否则我会得到错误:默认数据源未配置,但持久化单元“”使用它。我使用的实际数
我希望使用动态接受主题作为查询参数的成功/失败响应来响应RESTendpoint。在带有小型反应式消息传递的Quakus中,代码看起来就像下面用OutgoingKafkaRecordMetadata包装有效负载一样 即https://myendpoint/PublishToKafka?主题=myDynamicTopic 从Quarkus doco“如果endpoint没有返回CompletionS
我正在将一套相关的应用程序从WebLogic移植到JBoss EAPV6.2。 我已经使用JBoss命令行界面设置了一个数据源连接,并将其挂钩到oracle数据库。根据JBoss标准,该数据库的名称为“myDataSource”,而JNDI名称为“java:JBoss/datasources/myDataSource”。我可以测试和验证这个数据库连接。 但是,当我尝试移植代码并运行它时,连接不起作
在面向资源的API中,资源是命名实体,资源名称是资源的标识符。每个资源必须有其唯一的资源名称。资源名称由资源ID本身,父资源的ID和资源对应的API服务名称组成。在下文,我们将探讨资源ID和如何构建资源名称。 gRPC API应该使用无模式的URIs作为资源名称。它们通常遵循REST URL的惯例并且表现得更像网络文件路径。它们可以轻松的映射到REST URL上:细节请参考下一节标准方法。 资源组
我将我的项目更新为spring boot 2.1.0版。释放 现在我得到以下错误: 使用本期介绍的属性https://github.com/spring-projects/spring-boot/issues/14778似乎对解决我的问题没有效果。 如何为cassandra禁用jmx? 我目前的cassandra配置如下:
如何为不支持流式处理的数据库提供反应式流 API?比如说dymodb。执行 get 调用时,dynamodb 将返回所有结果。因此,即使我将 get 调用包装在源中,如何处理来自下游阶段的背压?另外,如何实现写入 db 中的写入调用?我的水槽会是什么样子?任何关于此的指针都会有所帮助。