← Docs

Spring Boot

Gold Lapel ships Spring Boot support as a separate Maven artifact (goldlapel-spring-boot) that pulls in the Java wrapper transitively. Add the dependency, and auto-configuration wires Gold Lapel into your DataSource.

Install

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

The starter pulls in the core goldlapel library transitively — one dependency entry is enough. Spring Data JPA, Spring JDBC, and any other code on top of the Spring DataSource flows through Gold Lapel.

Use

No configuration required. Keep your existing datasource config:

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

The auto-configuration 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 with it — repeated reads serve in microseconds. Application code, @Entity classes, JpaRepository interfaces, and connection pool settings all stay as they are.

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

Auto-configuration is the usual path — most apps never need to call Gold Lapel directly. For finer-grained control (multiple datasources, runtime options beyond the YAML keys), drop down to the factory API. JDBC URLs cannot 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;
}

Tuning

goldlapel.extra-args passes any CLI flag through to the binary. GOLDLAPEL_* environment variables are honoured as well. The configuration reference documents every option.

Requirements

  • Java 17+
  • Spring Boot 3.x
  • Spring Data JPA or Spring JDBC (anything that consumes the Spring DataSource)
  • HikariCP (Spring Boot's default 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 transparent to Spring Data JPA and the application.

For the underlying Java wrapper API — GoldLapel.start(), JDBC helpers, the reactive flavour, and the wrapper methods — see the Java guide.