← Docs

Spring Boot + Spring Data JPA

Auto-configuration starter that wires Gold Lapel into your Spring DataSource. Your existing application.yml keeps working.

Install

<dependency>
    <groupId>com.goldlapel</groupId>
    <artifactId>goldlapel</artifactId>
    <version>0.2.0</version>
</dependency>
<dependency>
    <groupId>com.goldlapel</groupId>
    <artifactId>goldlapel-spring-boot</artifactId>
    <version>0.2.0</version>
</dependency>

As of v0.2, the Spring Boot autoconfig lives in its own artifact (goldlapel-spring-boot) alongside the core goldlapel library. Add both to your pom.xml (or the Gradle equivalent). Spring Data JPA, Spring JDBC, and any other JPA/ JDBC code on top of the Spring DataSource will flow through Gold Lapel automatically.

Usage

Zero configuration required. Keep your existing datasource config:

spring:
  datasource:
    url: jdbc:postgresql://db:5432/mydb
    username: myapp
    password: s3cret

The autoconfig ships a BeanPostProcessor that spawns a Gold Lapel proxy in front of your upstream database and swaps the DataSource's JDBC URL for the proxy's before Hikari opens any pool connections. The L1 native cache activates automatically — repeated reads serve in microseconds. Your application code, @Entity classes, JpaRepository interfaces, and connection pool settings all stay exactly as they are.

v0.2 fixes a credential-handling bug in the post-processor. It now correctly reads spring.datasource.username/.password and injects them into the upstream connection string, so your existing Spring datasource config works without modification.

Configuration

Optional proxy settings via application.yml:

goldlapel:
  port: 9000
  extra-args:
    - "--threshold-duration-ms"
    - "200"

Or application.properties:

goldlapel.port=9000
goldlapel.extra-args=--threshold-duration-ms,200

To disable without removing the dependency:

goldlapel:
  enabled: false
KeyDefaultDescription
goldlapel.enabledtrueSet to false to disable the proxy
goldlapel.port7932Local proxy listen port
goldlapel.extra-args[]Extra CLI args passed to the Gold Lapel binary

Dropping down to the Java API

Spring Boot users rarely need to call Gold Lapel directly — the autoconfig handles it. If you want finer-grained control (multiple datasources, runtime options beyond the three YAML keys, etc.), you can drop down to the v0.2 factory API. JDBC URLs can't carry inline user:pass, so Gold Lapel exposes getJdbcUrl(), getJdbcUser(), and getJdbcPassword() helpers:

import com.goldlapel.GoldLapel;

GoldLapel gl = GoldLapel.start(
    "postgresql://user:pass@db:5432/mydb",
    opts -> opts.port(7932)
                .config(Map.of("mode", "waiter", "poolSize", 50))
);

// JDBC can't parse inline userinfo, so use these helpers
String jdbcUrl  = gl.getJdbcUrl();       // jdbc:postgresql://127.0.0.1:7932/mydb
String jdbcUser = gl.getJdbcUser();      // user
String jdbcPass = gl.getJdbcPassword();  // pass

HikariDataSource ds = new HikariDataSource();
ds.setJdbcUrl(jdbcUrl);
ds.setUsername(jdbcUser);
ds.setPassword(jdbcPass);

Multiple DataSources

Each datasource needs its own proxy port. Since goldlapel.* properties are global, configure per-datasource via the Java API directly:

import com.goldlapel.GoldLapel;

@Bean
public DataSource ordersDataSource() {
    GoldLapel gl = GoldLapel.start(
        "postgresql://user:pass@db1:5432/orders",
        opts -> opts.port(7932)
    );
    HikariDataSource ds = new HikariDataSource();
    ds.setJdbcUrl(gl.getJdbcUrl());
    ds.setUsername(gl.getJdbcUser());
    ds.setPassword(gl.getJdbcPassword());
    return ds;
}

@Bean
public DataSource analyticsDataSource() {
    GoldLapel gl = GoldLapel.start(
        "postgresql://user:pass@db2:5432/analytics",
        opts -> opts.port(7942)
    );
    HikariDataSource ds = new HikariDataSource();
    ds.setJdbcUrl(gl.getJdbcUrl());
    ds.setUsername(gl.getJdbcUser());
    ds.setPassword(gl.getJdbcPassword());
    return ds;
}

Advanced Tuning

Use goldlapel.extra-args to pass any CLI flag to the binary, or set GOLDLAPEL_* environment variables. The configuration reference documents every option in detail.

Requirements

  • Java 17+
  • Spring Boot 3.x
  • Spring Data JPA or Spring JDBC (anything that consumes the Spring DataSource)
  • HikariCP (Spring Boot's default connection pool)
  • PostgreSQL JDBC driver on the classpath

How It Works

When Spring Boot creates a HikariDataSource, the goldlapel-spring-boot BeanPostProcessor:

  1. Reads spring.datasource.url, spring.datasource.username, and spring.datasource.password and assembles the upstream Postgres URL (strips the jdbc: prefix and folds userinfo in)
  2. Calls GoldLapel.start(upstream, opts -> ...) to spawn the proxy
  3. Rewrites the DataSource's JDBC URL and credentials to gl.getJdbcUrl()/getJdbcUser()/getJdbcPassword()

This happens before Hikari opens any pool connections, so the rewrite is completely transparent to Spring Data JPA and your application.

Upgrading from v0.1

v0.2 splits the Spring Boot autoconfig out of the core library and adopts a static-factory + JDBC-helper API. Update your pom.xml to pull in both artifacts:

<!-- v0.1 (old) — single artifact, autoconfig baked into goldlapel -->
<dependency>
    <groupId>com.goldlapel</groupId>
    <artifactId>goldlapel</artifactId>
    <version>0.1.0</version>
</dependency>

<!-- v0.2 (new) — split into core + Spring Boot autoconfig -->
<dependency>
    <groupId>com.goldlapel</groupId>
    <artifactId>goldlapel</artifactId>
    <version>0.2.0</version>
</dependency>
<dependency>
    <groupId>com.goldlapel</groupId>
    <artifactId>goldlapel-spring-boot</artifactId>
    <version>0.2.0</version>
</dependency>

If you were calling the Java API directly (e.g. for multi-datasource setups), switch from new GoldLapel(...).start() to GoldLapel.start(url, opts -> ...), and use the JDBC-specific accessors when building HikariDataSources:

// v0.1 (old) — new GoldLapel() + .start() returned a Connection
GoldLapel gl = new GoldLapel("postgresql://user:pass@db/mydb",
    new GoldLapel.Options().port(7932));
Connection conn = gl.start();

// v0.2 (new) — static factory + JDBC helper accessors
GoldLapel gl = GoldLapel.start(
    "postgresql://user:pass@db/mydb",
    opts -> opts.port(7932)
);
String jdbcUrl  = gl.getJdbcUrl();
String jdbcUser = gl.getJdbcUser();
String jdbcPass = gl.getJdbcPassword();
  • Spring Boot autoconfig moved from goldlapel to a separate goldlapel-spring-boot artifact — add both.
  • GoldLapel.start(url, opts -> ...) is the factory — no more new GoldLapel(...).
  • Use getJdbcUrl(), getJdbcUser(), getJdbcPassword() when wiring a HikariDataSource — JDBC URLs reject inline userinfo.
  • The post-processor now correctly handles spring.datasource.username/.password.