如何在启动应用程序时禁用 Javers 创建表
How to disable Javers from creating Tables when starting application
我正在尝试处理由于 Javers table 创建错误而无法启动的应用程序(问题是由于应用程序数据库问题)。有没有一种方法可以防止 javers 在应用程序启动期间创建 tables(tables,例如 jv_commit),这样我就可以在 DBA 修复数据库问题时处理应用程序(这将花点时间)?
我在 application.yml 中添加了以下内容(不确定这样做是否正确)
Javers:
sqlSchemaManagementEnabled: false
auditableAspectEnabled: false
springDataAuditableRepositoryAspectEnabled: false
我也在所有存储库 类 中注释掉了@JaversSpringDataAuditable。
使用了 Javers 依赖项
<dependency>
<groupId>org.javers</groupId>
<artifactId>javers-spring-jpa</artifactId>
<version>5.7.0</version>
</dependency>
错误日志
2019-10-16 16:51:32,796 25724 INFO [main] o.p.core.schema.SchemaManagerImpl [SchemaManagerImpl.java:51] --- creating entity with name jv_commit using ddl:
CREATE TABLE jv_commit (
commit_pk NUMBER NOT NULL,
author VARCHAR2(200),
commit_date TIMESTAMP,
commit_date_instant VARCHAR2(30),
commit_id NUMBER(22,2),
CONSTRAINT jv_commit_pk PRIMARY KEY(commit_pk)
)
2019-10-16 16:51:33,903 25724 WARN [main] o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext [AbstractApplicationContext.java:557] --- Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'javers' defined in class path resource [com/common/audit/JaversSpringJpaApplicationConfig.class]: Invocation of init method failed; nested exception is org.polyjdbc.core.exception.SchemaManagerException: [DDL_ERROR] Failed to run DDL:
CREATE TABLE jv_commit (
commit_pk NUMBER NOT NULL,
author VARCHAR2(200),
commit_date TIMESTAMP,
commit_date_instant VARCHAR2(30),
commit_id NUMBER(22,2),
CONSTRAINT jv_commit_pk PRIMARY KEY(commit_pk)
)
2019-10-16 16:51:33,935 25724 INFO [main] o.s.o.j.LocalContainerEntityManagerFactoryBean [AbstractEntityManagerFactoryBean.java:597] --- Closing JPA EntityManagerFactory for persistence unit 'default'
2019-10-16 16:51:33,938 25724 INFO [main] com.zaxxer.hikari.HikariDataSource [HikariDataSource.java:350] --- HikariPool-1 - Shutdown initiated...
2019-10-16 16:51:36,487 25724 INFO [main] com.zaxxer.hikari.HikariDataSource [HikariDataSource.java:352] --- HikariPool-1 - Shutdown completed.
2019-10-16 16:51:36,493 25724 INFO [main] o.a.catalina.core.StandardService [DirectJDKLog.java:173] --- Stopping service [Tomcat]
2019-10-16 16:51:36,496 25724 INFO [main] c.v.u.c.filter.AuditLoggingFilter [AuditLoggingFilter.java:195] --- in Filter destroy method
2019-10-16 16:51:36,516 25724 WARN [main] o.a.c.loader.WebappClassLoaderBase [DirectJDKLog.java:173] --- The web application [ROOT] appears to have started a thread named [RxIoScheduler-1 (Evictor)] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093)
java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:745)
2019-10-16 16:51:36,528 25724 INFO [main] o.s.b.a.l.ConditionEvaluationReportLoggingListener [ConditionEvaluationReportLoggingListener.java:135] ---
sqlSchemaManagementEnabled
开关由 JaVers Spring 启动器管理,参见 https://javers.org/documentation/spring-boot-integration/
如果您不使用启动器,则不会读取开关,但您仍然可以在构建 Javers 实例时设置此开关:
def javers = JaversBuilder.javers()
.registerJaversRepository(sqlRepository()
.withConnectionProvider({ DriverManager.getConnection("jdbc:h2:mem:empty-test") } as ConnectionProvider)
.withSchemaManagementEnabled(false)
.withDialect(getDialect())
.build()).build()
我正在尝试处理由于 Javers table 创建错误而无法启动的应用程序(问题是由于应用程序数据库问题)。有没有一种方法可以防止 javers 在应用程序启动期间创建 tables(tables,例如 jv_commit),这样我就可以在 DBA 修复数据库问题时处理应用程序(这将花点时间)?
我在 application.yml 中添加了以下内容(不确定这样做是否正确)
Javers:
sqlSchemaManagementEnabled: false
auditableAspectEnabled: false
springDataAuditableRepositoryAspectEnabled: false
我也在所有存储库 类 中注释掉了@JaversSpringDataAuditable。
使用了 Javers 依赖项
<dependency>
<groupId>org.javers</groupId>
<artifactId>javers-spring-jpa</artifactId>
<version>5.7.0</version>
</dependency>
错误日志
2019-10-16 16:51:32,796 25724 INFO [main] o.p.core.schema.SchemaManagerImpl [SchemaManagerImpl.java:51] --- creating entity with name jv_commit using ddl:
CREATE TABLE jv_commit (
commit_pk NUMBER NOT NULL,
author VARCHAR2(200),
commit_date TIMESTAMP,
commit_date_instant VARCHAR2(30),
commit_id NUMBER(22,2),
CONSTRAINT jv_commit_pk PRIMARY KEY(commit_pk)
)
2019-10-16 16:51:33,903 25724 WARN [main] o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext [AbstractApplicationContext.java:557] --- Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'javers' defined in class path resource [com/common/audit/JaversSpringJpaApplicationConfig.class]: Invocation of init method failed; nested exception is org.polyjdbc.core.exception.SchemaManagerException: [DDL_ERROR] Failed to run DDL:
CREATE TABLE jv_commit (
commit_pk NUMBER NOT NULL,
author VARCHAR2(200),
commit_date TIMESTAMP,
commit_date_instant VARCHAR2(30),
commit_id NUMBER(22,2),
CONSTRAINT jv_commit_pk PRIMARY KEY(commit_pk)
)
2019-10-16 16:51:33,935 25724 INFO [main] o.s.o.j.LocalContainerEntityManagerFactoryBean [AbstractEntityManagerFactoryBean.java:597] --- Closing JPA EntityManagerFactory for persistence unit 'default'
2019-10-16 16:51:33,938 25724 INFO [main] com.zaxxer.hikari.HikariDataSource [HikariDataSource.java:350] --- HikariPool-1 - Shutdown initiated...
2019-10-16 16:51:36,487 25724 INFO [main] com.zaxxer.hikari.HikariDataSource [HikariDataSource.java:352] --- HikariPool-1 - Shutdown completed.
2019-10-16 16:51:36,493 25724 INFO [main] o.a.catalina.core.StandardService [DirectJDKLog.java:173] --- Stopping service [Tomcat]
2019-10-16 16:51:36,496 25724 INFO [main] c.v.u.c.filter.AuditLoggingFilter [AuditLoggingFilter.java:195] --- in Filter destroy method
2019-10-16 16:51:36,516 25724 WARN [main] o.a.c.loader.WebappClassLoaderBase [DirectJDKLog.java:173] --- The web application [ROOT] appears to have started a thread named [RxIoScheduler-1 (Evictor)] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093)
java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:745)
2019-10-16 16:51:36,528 25724 INFO [main] o.s.b.a.l.ConditionEvaluationReportLoggingListener [ConditionEvaluationReportLoggingListener.java:135] ---
sqlSchemaManagementEnabled
开关由 JaVers Spring 启动器管理,参见 https://javers.org/documentation/spring-boot-integration/
如果您不使用启动器,则不会读取开关,但您仍然可以在构建 Javers 实例时设置此开关:
def javers = JaversBuilder.javers()
.registerJaversRepository(sqlRepository()
.withConnectionProvider({ DriverManager.getConnection("jdbc:h2:mem:empty-test") } as ConnectionProvider)
.withSchemaManagementEnabled(false)
.withDialect(getDialect())
.build()).build()