3

我正在尝试使用 spring boot 运行集成测试并收到以下错误:

Caused by: org.springframework.context.ApplicationContextException:
Failed to start bean 'SchedulerFactory'; nested exception is org.springframework.scheduling.SchedulingException:
Could not start Quartz Scheduler; nested exception is org.quartz.SchedulerConfigException: 
Failure occured during job recovery. [See nested exception:
org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: Table "QRTZ_LOCKS" not found; SQL statement:
SELECT * FROM QRTZ_LOCKS UPDLOCK WHERE LOCK_NAME = ? [42102-193] [See nested exception: org.h2.jdbc.JdbcSQLException: Table "QRTZ_LOCKS" not found; SQL statement:
SELECT * FROM QRTZ_LOCKS UPDLOCK WHERE LOCK_NAME = ? [42102-193]]]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:176)

很明显,QRTZ没有创建表。我可以手动创建它们,但是当它们不存在时,spring boot 是否真的无法创建它们?如果是这样,看起来很奇怪,因为这些表只需要在启动时创建一次,并且像 sql 语句create if not exisit就足够了。那么spring boot可以自动创建QRTZ表吗?

4

1 回答 1

4

不,spring boot 不会自动创建石英表。如果要自动创建,则需要使用 Spring Boot 的 Datasource Initializer 功能,它将自动为您创建表。

如您所知,Spring Boot 提供了一个很棒的框架,在开发 Spring 应用程序时为开发人员节省了大量时间和精力。它的一大特点是数据库初始化。您可以使用 spring boot 来初始化您的 sql 数据库。

org.springframework:spring-jdbc 依赖是辅助数据库初始化的依赖。

您只需要将 schema.sql 文件添加到资源文件夹,以便将其加载到类路径。schema.sql 文件将包含我们数据库所需的所有表定义,这里是石英模式(在石英分布中找到这个)。下一个要添加的文件是资源文件夹中的 data.sql。该文件将包含填充我们的数据库所需的 sql 语句。石英忽略这个。

在初始化时,spring boot 将搜索 schema.sql 和 data.sql 文件并使用数据库初始化程序执行它们。

于 2017-02-19T14:49:41.493 回答