Che*_*rry 3 java spring quartz quartz-persistence
我正在尝试使用 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)
Run Code Online (Sandbox Code Playgroud)
很明显,QRTZ表没有创建。我可以手动创建它们,但是当它们不存在时,Spring Boot 是否无法创建它们?如果是这样的话看起来很奇怪,因为这些表只需要在启动时创建一次,像这样的sql语句create if not exisit就足够了。那么spring boot可以自动创建QRTZ表吗?
不,Spring Boot 不会自动创建石英表。如果您想自动创建该表,则需要使用 Spring Boot 的数据源初始化程序功能,它将自动为您创建表。
正如您所知,Spring boot 提供了一个出色的框架,为开发人员在开发 Spring 应用程序时节省了大量的时间和精力。它的一大特点是数据库初始化。您可以使用 spring boot 来初始化您的 sql 数据库。
org.springframework:spring-jdbc依赖是辅助数据库初始化的依赖。
您只需将 schema.sql 文件添加到资源文件夹中,以便将其加载到类路径中。schema.sql 文件将包含我们的数据库所需的所有表定义,这里是quartz 模式(在quartz 发行版中找到它)。下一个要添加的文件是资源文件夹中的 data.sql。该文件将包含填充数据库所需的 sql 语句。对于石英,请忽略这一点。
在初始化时,Spring Boot 将搜索 schema.sql 和 data.sql 文件并使用数据库初始化程序执行它们。
| 归档时间: |
|
| 查看次数: |
6329 次 |
| 最近记录: |