fix:修复SQLite写操作[SQLITE_BUSY_SNAPSHOT]

This commit is contained in:
czhqwer
2025-03-30 23:19:04 +08:00
parent 9bc416a2e8
commit d7633d3280

View File

@@ -1,5 +1,6 @@
package cn.czh.config;
import com.zaxxer.hikari.HikariDataSource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.jdbc.DataSourceBuilder;
@@ -49,10 +50,15 @@ public class DataSourceConfig {
} else {
log.info("Using SQLite database.");
// 默认使用 SQLite无需 username 和 password
return DataSourceBuilder.create()
DataSource dataSource = DataSourceBuilder.create()
.url(defaultUrl)
.driverClassName(defaultDriverClassName)
.build();
// SQLite是轻量数据库默认不支持并发设置连接池参数确保只有一个连接
if (dataSource instanceof HikariDataSource) {
((HikariDataSource) dataSource).setMaximumPoolSize(1);
}
return dataSource;
}
}