Spring Boot starter that auto-configures Celesta inside a Spring Boot application.
Celesta is a Java data-access and database-migration library: you describe your schema once in CelestaSQL, Celesta generates type-safe data-access classes (cursors) and keeps the physical database in sync with that description across all supported RDBMS (PostgreSQL, Oracle, MS SQL Server, H2, Firebird, …).
This starter wires Celesta into the Spring context so that you get:
- a ready-to-use
Celestabean, configured fromapplication.yml/application.properties; - a connection pool built either from your own
DataSourcebean or fromcelesta.jdbc.*settings; - declarative transaction management for Celesta procedures via the
@CelestaTransactionannotation; - IDE auto-completion for all
celesta.*configuration properties.
| Version | |
|---|---|
| Java | 17 or newer |
| Spring Boot | 3.x |
| Celesta | 8.2.x |
Need Spring Boot 2.x / Java 11? Use the
3.0.xline of this starter.
Maven:
<dependency>
<groupId>ru.curs</groupId>
<artifactId>spring-boot-starter-celesta</artifactId>
<version>3.1.0</version>
</dependency>Gradle:
implementation 'ru.curs:spring-boot-starter-celesta:3.1.0'(Check the Maven Central badge above for the latest released version.)
Put CelestaSQL scripts (*.sql) under a score directory, e.g. src/main/resources/score:
CREATE SCHEMA demo VERSION '1.0';
CREATE TABLE OrderHeader (
id VARCHAR(30) NOT NULL,
date DATETIME,
customer VARCHAR(50),
CONSTRAINT pk_OrderHeader PRIMARY KEY (id)
);Add the celesta-maven-plugin to your build to
generate the cursor classes (e.g. OrderHeaderCursor) from these scripts, and point the starter at
the score:
celesta:
score-path: classpath:scoreOn application startup Celesta validates the score and automatically migrates the target database to match it.
Inject the generated cursors (or use a CallContext directly) inside a method annotated with
@CelestaTransaction:
import org.springframework.stereotype.Service;
import ru.curs.celesta.CallContext;
import ru.curs.celesta.transaction.CelestaTransaction;
@Service
public class OrderService {
@CelestaTransaction
public void createOrder(CallContext ctx, String id, String customer) {
OrderHeaderCursor order = new OrderHeaderCursor(ctx)
order.setId(id)
.setCustomer(customer)
.insert();
}
}The caller supplies a CallContext (which carries the current user identity):
CallContext ctx = new CallContext("alice");
//orderService must be a Spring bean
orderService.createOrder(ctx, "ORD-1", "ACME");@CelestaTransaction marks a method as a Celesta procedure entry point. When the method has a
CallContext argument, the starter's aspect:
- activates the
CallContextagainst theCelestainstance (opening a JDBC connection), - invokes the method,
- commits on normal return, or rolls back if the method throws,
- closes the
CallContextin afinallyblock.
Nested @CelestaTransaction calls that receive an already-active CallContext simply join the
existing transaction instead of starting a new one, so you can compose procedures freely. If the
method has no CallContext argument, it is invoked without transaction handling.
The Celesta connection pool is chosen automatically:
- Your
DataSourcebean — if a singlejavax.sql.DataSourcebean is present in the context (e.g. a HikariCP pool configured viaspring.datasource.*), Celesta uses it. This lets Celesta share connections with the rest of your Spring application. celesta.jdbc.*— if noDataSourcebean exists, Celesta builds its own internal pool from thecelesta.jdbc.url/username/passwordsettings.- In-memory H2 — if neither is provided, Celesta falls back to an in-memory H2 database, which is handy for tests and demos.
All properties live under the celesta prefix. Spring Boot relaxed binding applies, so
scorePath, score-path and SCORE_PATH are equivalent.
| Property | Type | Default | Description |
|---|---|---|---|
celesta.score-path |
String | — | Comma-separated list of score location patterns, e.g. classpath:score, classpath*:score, file:///opt/app/score. |
celesta.jdbc.url |
String | — | JDBC connection URL (used when no DataSource bean is present). |
celesta.jdbc.username |
String | — | JDBC user name. |
celesta.jdbc.password |
String | — | JDBC password. |
celesta.h2.in-memory |
boolean | false |
Start an in-memory H2 database. |
celesta.h2.referential-integrity |
boolean | false |
Enable H2 referential integrity. |
celesta.h2.port |
Integer | — | Start the H2 web console on the given port. |
celesta.skip-db-update |
boolean | false |
Skip database migration on startup. |
celesta.force-db-initialize |
boolean | false |
Force database initialization on startup. |
celesta.log-logins |
boolean | false |
Log all login and logout actions. |
celesta.celesta-scan |
Set<String> | — | Packages scanned for Celesta-annotated components. |
celesta:
score-path: classpath:score
jdbc:
url: jdbc:postgresql://localhost:5432/demo
username: demo
password: demo
skip-db-update: false
log-logins: truemvn clean verify -P devThe dev profile additionally runs Checkstyle and SpotBugs. The build requires JDK 17+.
Licensed under the Apache License, Version 2.0.