0. 为啥感觉升级了 win11 之后,电脑像是刚买回来的,很快
这篇加餐完全是一个意外:时隔两年半,再看 Springboot-quartz-starter 集成实现的时候,不知道为啥我的h2 在应用启动的时候,不能自动创建quartz相关的schema。后面看了 springboot 的文档,据说是可以做到的,AI也是这么说的。
没办法,只能看 QuartzAutoConfiguration 源码了。于是乎,就有了这么个好活
没办法,就当是一个支线任务了
1. AbstractScriptDatabaseInitializer

下面是熟悉的,阉割后的 源码
package org.springframework.boot.sql.init;
/**
* Base class for an {@link InitializingBean} that performs SQL database initialization
* using schema (DDL) and data (DML) scripts.
*
* @author Andy Wilkinson
* @since 2.5.0
*/
public abstract class AbstractScriptDatabaseInitializer implements ResourceLoaderAware, InitializingBean {
// 构造入参配置
private final DatabaseInitializationSettings settings;
private volatile ResourceLoader resourceLoader;
@Override
public void afterPropertiesSet() throws Exception {
// 初始化后,就执行逻辑了
initializeDatabase();
}
/**
* Initializes the database by applying schema and data scripts.
* @return {@code true} if one or more scripts were applied to the database, otherwise
* {@code false}
*/
public boolean initializeDatabase() {
ScriptLocationResolver locationResolver = new ScriptLocationResolver(this.resourceLoader);
// 先后执行 schema, data 的脚本
boolean initialized = applySchemaScripts(locationResolver);
return applyDataScripts(locationResolver) || initialized;
}
// 真正执行脚本前,会走这个判断,决定是否要执行脚本
private boolean isEnabled() {
if (this.settings.getMode() == DatabaseInitializationMode.NEVER) {
return false;
}
return this.settings.getMode() == DatabaseInitializationMode.ALWAYS || isEmbeddedDatabase();
}
/**
* Returns whether the database that is to be initialized is embedded.
* @return {@code true} if the database is embedded, otherwise {@code false}
* @since 2.5.1
*/
protected boolean isEmbeddedDatabase() {
throw new IllegalStateException(
"Database initialization mode is '" + this.settings.getMode() + "' and database type is unknown");
}
private boolean applySchemaScripts(ScriptLocationResolver locationResolver) {
return applyScripts(this.settings.getSchemaLocations(), "schema", locationResolver);
}
private boolean applyDataScripts(ScriptLocationResolver locationResolver) {
return applyScripts(this.settings.getDataLocations(), "data", locationResolver);
}
private boolean applyScripts(List<String> locations, String type, ScriptLocationResolver locationResolver) {
List<Resource> scripts = getScripts(locations, type, locationResolver);
if (!scripts.isEmpty() && isEnabled()) {
runScripts(scripts);
return true;
}
return false

最低0.47元/天 解锁文章
10万+

被折叠的 条评论
为什么被折叠?



