DFS Binder Database
Transitional binder for small files when object storage is unavailable. S3 is recommended for production and large files.
<dependency>
<groupId>io.github.loadup-cloud</groupId>
<artifactId>loadup-components-dfs-binder-database</artifactId>
</dependency>Select it with loadup.dfs.binder-type=database. Flyway creates the PostgreSQL dfs_file table. The binder uses Spring
JDBC, stores file bytes in BYTEA, and stores JSON metadata as text. It supports the common CRUD and metadata
capabilities only; presigned URLs and multipart upload are unsupported.
接入步骤
在引入 loadup-framework-bom BOM 的应用中添加:
<dependency><groupId>io.github.loadup-cloud</groupId><artifactId>loadup-components-dfs-binder-database</artifactId></dependency>通过 loadup.dfs.binder-type 选择 local、s3 或 database;业务层注入 DfsTemplate。
此 jar 负责接入具体技术实现;业务模块继续面向 API/facade 编程。
对外契约
DatabaseDfsTemplateimplementsDfsTemplate.DfsFileInsertmaps thedfs_filetable.
自动装配
-
DatabaseDfsAutoConfiguration- 启用条件:
@ConditionalOnProperty(prefix = "loadup.dfs", name = "binder-type", havingValue = "database")。
- 启用条件:
设计边界与装配路径见 ARCHITECTURE.md。
最小配置
loadup:
dfs:
binder-type: database同一应用只启用与该值对应的 binder;其他可选项见下方配置类及父模块 README。
默认时区
日期默认使用 JVM 系统本地时区;无偏移日期按本地时区解释,显式偏移和 epoch 时间保持绝对时间语义。
Spring 装配使用 loadup-components-runtime 提供的应用 JSON mapper / Clock;消费者通过参数注入,不创建默认兜底实例。独立测试需显式提供所需 Bean。
设计与实现
职责与边界
文件存储的具体后端适配模块;由集成方按需引入。
Maven 依赖边界
直接依赖的框架模块:
loadup-components-dfs-apiloadup-components-database
直接依赖的外部坐标(不含测试与 provided scope):
org.springframework.boot:spring-boot-starter-flywayorg.flywaydb:flyway-mysqltools.jackson.core:jackson-databindorg.springframework.boot:spring-boot-autoconfigure
实现入口
主要入口文件:
分层与调用路径
DatabaseDfsTemplate 直接实现 DfsTemplate,通过 PostgreSQL 读写文件内容和元数据。
业务代码 → API/facade → 当前 binder → 第三方引擎或基础设施binder 实现框架契约,把实现库及其配置隔离在业务 API 之外。
装配规则
-
DatabaseDfsAutoConfiguration是自动配置入口。@ConditionalOnClass({NamedParameterJdbcTemplate.class, ObjectMapper.class})@ConditionalOnProperty(prefix = "loadup.dfs", name = "binder-type", havingValue = "database")@ConditionalOnMissingBean(DfsTemplate.class)
扩展契约
DfsFileInsertMapperis generated fromDfsFileInsertby MyBatis-Flex;DatabaseDfsTemplateuses it for file reads and inserts.
设计取舍
选择独立 binder,使文件存储实现的依赖留在集成应用;替换底层实现时,业务侧仍使用 DfsTemplate 契约。
集成方式与配置示例见 README.md。
默认时区
日期默认使用 JVM 系统本地时区;无偏移日期按本地时区解释,显式偏移和 epoch 时间保持绝对时间语义。