2

我从 Quarkus 网站建立了一个 Quarkus/Kotlin/Gradle 项目。我正在尝试使用 hibernate/panache/reactive 制作一个简单的反应式 api:

  • Quarkus 1.13.6.Final
  • 摇篮 6.9
  • 科特林 1.4.32
  • 夸库斯-科特林
  • 夸库斯弧
  • quarkus-hibernate-reactive-panache
  • quarkus 反应式 pg 客户端
  • quarkus-resteasy-reactive-jackson

接口:

@Path("incidents")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
class IncidentResource {

    @Inject
    lateinit var incidentRepository: IncidentRepository

    @GET
    @Path("hello")
    @Produces(MediaType.TEXT_PLAIN)
    fun getHello(): String = "hello"

    @GET
    fun get(): Uni<List<Incident>> = incidentRepository.findAll().list()
}

模型:

@Entity
data class Incident(
        @Id
        @GeneratedValue
        @field:JsonProperty("id")
        val id: String,

        @Column(nullable = false)
        @field:JsonProperty("summary")
        val summary: String,
)

存储库:

@ApplicationScoped
class IncidentRepository : PanacheRepository<Incident> {
}

/incidents/hello 路径工作正常,但 /incidents 给我一个错误:

Request failed : javax.enterprise.inject.UnsatisfiedResolutionException: No bean found for required type [interface javax.transaction.TransactionManager] and qualifiers [[]]
        at io.quarkus.arc.impl.InstanceImpl.bean(InstanceImpl.java:175)
        at io.quarkus.arc.impl.InstanceImpl.getInternal(InstanceImpl.java:196)
        at io.quarkus.arc.impl.InstanceImpl.get(InstanceImpl.java:93)
        at io.smallrye.context.jta.context.propagation.JtaContextProvider.tm(JtaContextProvider.java:120)
        at io.smallrye.context.jta.context.propagation.JtaContextProvider.currentContext(JtaContextProvider.java:34)
        at io.smallrye.context.impl.ThreadContextProviderPlan.takeThreadContextSnapshots(ThreadContextProviderPlan.java:72)
        at io.smallrye.context.impl.SlowCapturedContextState.<init>(SlowCapturedContextState.java:25)
        at io.smallrye.context.SmallRyeThreadContext.captureContext(SmallRyeThreadContext.java:729)
        at io.smallrye.context.SmallRyeThreadContext.contextualSupplier(SmallRyeThreadContext.java:719)
        at io.smallrye.mutiny.context.BaseContextPropagationInterceptor.decorate(BaseContextPropagationInterceptor.java:27)
        at io.smallrye.mutiny.infrastructure.Infrastructure.decorate(Infrastructure.java:124)
        at io.smallrye.mutiny.groups.UniCreate.completionStage(UniCreate.java:134)
        at org.hibernate.reactive.mutiny.impl.MutinySessionFactoryImpl.uni(MutinySessionFactoryImpl.java:62)
        at org.hibernate.reactive.mutiny.impl.MutinyQueryImpl.uni(MutinyQueryImpl.java:40)
        at org.hibernate.reactive.mutiny.impl.MutinyQueryImpl.getResultList(MutinyQueryImpl.java:191)
        at io.quarkus.hibernate.reactive.panache.common.runtime.CommonPanacheQueryImpl.lambda$list$4(CommonPanacheQueryImpl.java:219)
        at io.quarkus.hibernate.reactive.panache.common.runtime.CommonPanacheQueryImpl.applyFilters(CommonPanacheQueryImpl.java:323)
        at io.quarkus.hibernate.reactive.panache.common.runtime.CommonPanacheQueryImpl.list(CommonPanacheQueryImpl.java:219)
        at io.quarkus.hibernate.reactive.panache.runtime.PanacheQueryImpl.list(PanacheQueryImpl.java:149)
        at com.alert.api.IncidentResource.get(IncidentResource.kt:26)
        at com.alert.api.IncidentResource_Subclass.get$$superaccessor5(IncidentResource_Subclass.zig:733)
        at com.alert.api.IncidentResource_Subclass$$function$$8.apply(IncidentResource_Subclass$$function$$8.zig:29)
        at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
        at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:62)
        at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.monitor(InvocationInterceptor.java:49)
        at io.quarkus.arc.runtime.devconsole.InvocationInterceptor_Bean.intercept(InvocationInterceptor_Bean.zig:521)
        at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
        at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
        at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
        at com.alert.api.IncidentResource_Subclass.get(IncidentResource_Subclass.zig:691)
        at com.alert.api.IncidentResource$quarkusrestinvoker$get_407a850349137c93edc5dab2a621b8699ccd0a7c.invoke(IncidentResource$quarkusrestinvoker$get_407a850349137c93edc5dab2a621b8699ccd0a7c.zig:33)
        at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
        at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:7)
        at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:122)
        at org.jboss.resteasy.reactive.server.handlers.RestInitialHandler.beginProcessing(RestInitialHandler.java:47)
        at org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveVertxHandler.handle(ResteasyReactiveVertxHandler.java:17)
        at org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveVertxHandler.handle(ResteasyReactiveVertxHandler.java:7)
        at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1038)
        at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:137)
        at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:132)
        at io.quarkus.vertx.http.runtime.StaticResourcesRecorder.lambda$start$1(StaticResourcesRecorder.java:65)
        at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1038)
        at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:101)
        at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:132)
        at io.vertx.ext.web.handler.impl.StaticHandlerImpl.lambda$sendStatic$1(StaticHandlerImpl.java:206)
        at io.vertx.core.impl.ContextImpl.lambda$null$0(ContextImpl.java:327)
        at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:366)
        at io.vertx.core.impl.EventLoopContext.lambda$executeAsync$0(EventLoopContext.java:38)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
        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:834)

我也有这个警告:

CDI: programmatic lookup problem detected
-----------------------------------------
At least one bean matched the required type and qualifiers but was marked as unused and removed during build
Removed beans:
        - CLASS bean io.smallrye.context.jta.context.propagation.JtaContextProvider$LifecycleManager [types=[class io.smallrye.context.jta.context.propagation.JtaContextProvider$LifecycleManager], qualifiers=[@javax.enterprise.inject.Default(), @javax.enterprise.inject.Any()]]
Required type: class io.smallrye.context.jta.context.propagation.JtaContextProvider$LifecycleManager
Required qualifiers: [@javax.enterprise.inject.Default()]

应用程序属性

quarkus.datasource.db-kind=postgresql
quarkus.datasource.username=test
quarkus.datasource.password=test

quarkus.hibernate-orm.database.generation=drop-and-create
quarkus.hibernate-orm.log.sql=true
quarkus.hibernate-orm.sql-load-script=import.sql

# Reactive config
quarkus.datasource.reactive.url=postgresql://localhost:5432/test

我找不到这个特定堆栈的适当示例或指南,我遵循了这个:https ://quarkus.io/guides/hibernate-orm-panache-kotlin 有 什么想法吗?

4

2 回答 2

1

它需要 quarkus-hibernate-orm-panache-kotlin 依赖项和 quarkus.datasource.jdbc=falseapplication.properties

于 2021-07-12T01:46:14.473 回答
0

TransactionManager实现可以在实现io.quarkus:quarkus-narayana-jta包中找到。

您的数据库 URL 需要如下所示:`quarkus.datasource.reactive.url=vertx-reactive:postgresql://...

另外,不要使用quarkus.hibernate-orm.database.generation=update配置,因为它需要 JDBC

于 2021-07-29T13:05:26.713 回答