当我尝试在& RESTEasy中使用Quarkus扩展时,我遇到了一个问题。启动应用程序时,会出现以下错误:
[io.qu.ru.Application] (Quarkus Main Thread) Failed to start application (with profile dev): java.lang.IllegalStateException: Booting an Hibernate Reactive serviceregistry on a non-reactive RecordedState!
at io.quarkus.hibernate.reactive.runtime.boot.registry.PreconfiguredReactiveServiceRegistryBuilder.checkIsReactive(PreconfiguredReactiveServiceRegistryBuilder.java:76)
at io.quarkus.hibernate.reactive.runtime.boot.registry.PreconfiguredReactiveServiceRegistryBuilder.<init>(PreconfiguredReactiveServiceRegistryBuilder.java:66)
at io.quarkus.hibernate.reactive.runtime.FastBootHibernateReactivePersistenceProvider.rewireMetadataAndExtractServiceRegistry(FastBootHibernateReactivePersistenceProvider.java:177)
at io.quarkus.hibernate.reactive.runtime.FastBootHibernateReactivePersistenceProvider.getEntityManagerFactoryBuilderOrNull(FastBootHibernateReactivePersistenceProvider.java:156)
at io.quarkus.hibernate.reactive.runtime.FastBootHibernateReactivePersistenceProvider.createEntityManagerFactory(FastBootHibernateReactivePersistenceProvider.java:82)
以下是相关的Quarkus配置:
quarkus:
datasource:
db-kind: "postgresql"
username: "sarah"
password: "connor"
jdbc:
~: true
url: "jdbc:postgresql://localhost:5432/mybase"
reactive:
~: true
url: "postgresql://localhost:5432/mybase"
以及相关的依赖关系:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-reactive-panache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-reactive-pg-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-flyway</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
使用~: false
禁用JDBC配置可以避免异常,但是应用程序不会在启动时启动Flyway迁移。在这种情况下,我看到以下信息:
[io.qu.ag.de.AgroalProcessor] (build-39) The Agroal dependency is present but no JDBC datasources have been defined.
在某些Quarkus问题上,我发现不可能同时运行反应性数据库连接和阻塞数据库连接,但是是否有一种方法可以让Flyway使用反应性 Quarkus应用程序?
发布于 2021-03-07 06:16:04
目前,它们似乎并不同时支持阻塞JDBC和反应性sql客户端。解决方法是为Quarkus运行时禁用JDBC,并编写自己的包装器来执行Flyway迁移。
下面的解决方法是基于他们相应的GitHub问题。
在应用程序启动时运行的天桥包装器:
@ApplicationScoped
public class RunFlyway {
@ConfigProperty(name = "myapp.flyway.migrate")
boolean runMigration;
@ConfigProperty(name = "quarkus.datasource.reactive.url")
String datasourceUrl;
@ConfigProperty(name = "quarkus.datasource.username")
String datasourceUsername;
@ConfigProperty(name = "quarkus.datasource.password")
String datasourcePassword;
public void runFlywayMigration(@Observes StartupEvent event) {
if (runMigration) {
Flyway flyway = Flyway.configure().dataSource("jdbc:" + datasourceUrl, datasourceUsername, datasourcePassword).load();
flyway.migrate();
}
}
}
pom.xml:
<!-- DB -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-reactive-pg-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-reactive</artifactId>
</dependency>
<!-- Flyway -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-flyway</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
application.yml:
myapp:
flyway:
migrate: true
quarkus:
datasource:
db-kind: postgresql
username: myuser
password: mypassword
jdbc: false
reactive:
url: postgresql://localhost:5432/mydb
https://stackoverflow.com/questions/66268122
复制