启动应用程序时如何禁止Javers创建表

时间:2019-10-16 11:27:12

标签: javers

我正在尝试处理由于Javers表创建错误而无法启动的应用程序(问题归因于应用程序数据库问题)。有没有一种方法可以防止Javers在应用程序启动期间创建表(如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] --- 

1 个答案:

答案 0 :(得分:1)

sqlSchemaManagementEnabled开关由JaVers Spring Boot启动程序管理,请参见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()