# Add e-signatures and clickwrap to Spring Boot

> Add e-signatures and clickwrap to Spring Boot with RestClient and one controller: POST /v1/sessions, GET /v1/records, Jackson records and the HttpSession.

Source: https://esigncomply.com/spring-boot

Stack · Spring Boot

To add e-signatures and clickwrap to Spring Boot, call the REST API with `RestClient`: there is no Java package, because the server SDK exists for Node.js only. One controller method creates the session with the secret key and keeps the pinned versions in the `HttpSession`, and another confirms the record. Esign Comply seals each acceptance as an independent record.

Follow the quickstart and each signature is a valid electronic signature under the U.S. ESIGN Act, state UETA laws and New York's ESRA, and each clickwrap is built the way courts require: clear notice of the terms, an unmistakable act of assent, and a sealed record of both.

[Get an API key](https://esigncomply.com/signup) · [Read the docs](https://esigncomply.com/docs/quickstart/spring-boot)

No Esign Comply artifact: spring-boot-starter-webmvc and spring-boot-starter-restclient

[Spring Boot quickstart](https://esigncomply.com/docs/quickstart/spring-boot)

Free plan: 10 live signatures a month and a full test mode. No card required.

Last updated November 26, 2026

Run in Spring Boot before publishing

**Session method**

src/main/java/com/example/quickstart/SignupController.java (excerpt)

```java
// Step 4: create the session with the secret key. The browser gets the client token only.
@PostMapping("/api/ceremony")
@ResponseBody
ResponseEntity<Map<String, Object>> ceremony(HttpServletRequest request) {
	// The page that runs the ceremony: the origin the browser reports, or the scheme and host the server saw.
	String origin = request.getHeader(HttpHeaders.ORIGIN);
	if (origin == null) {
		origin = ServletUriComponentsBuilder.fromContextPath(request).build().toUriString();
	}
	Answer<Session> answer = this.esc.call(HttpMethod.POST, "/sessions", Session.class, Map.of(
			"profile", this.profileId,
			"signer", SIGNER,
			"documents", List.of(
					Map.of("document", this.documents.get("terms"), "version", "current"),
					Map.of("document", this.documents.get("privacy"), "version", "current")),
			"context", Map.of("url", origin + "/signup", "locale", "en-US", "purpose", "account_signup")),
			"signup-" + SIGNER.get("external_id") + "-" + UUID.randomUUID());
	Session created = answer.body();
	if (answer.status() != 201) {
		String code = (created != null && created.error() != null) ? created.error().code() : "unknown";
		return ResponseEntity.status(HttpStatus.BAD_GATEWAY).body(Map.of("error", code));
	}

	// Server-owned state: the servlet session. The data stays in the memory of this server,
	// and the browser holds only the session ID in the JSESSIONID cookie.
	HttpSession session = request.getSession();
	session.setAttribute("signerId", SIGNER.get("external_id"));
	session.setAttribute("versionIds", created.documents().findValuesAsString("version_id").stream().sorted().toList());
	// The documents go to the browser as the API sent them: a JsonNode is written unchanged.
	return ResponseEntity.ok(Map.of("clientToken", created.clientToken(), "apiUrl", created.apiUrl(), "documents", created.documents()));
}
```

**The API call**

src/main/java/com/example/quickstart/EsignComply.java (excerpt)

```java
/** One call to the Esign Comply API. Returns the HTTP status and the JSON answer. */
<T> Answer<T> call(HttpMethod method, String path, Class<T> type, Object body, String idempotencyKey, Object... uriVariables) {
	ResponseEntity<T> response = send(method, path, type, body, idempotencyKey, uriVariables);
	// Rate limited: wait for the seconds in Retry-After, 1 at least and 5 at most, and send it again, twice at most.
	for (int attempt = 1; response.getStatusCode().value() == 429 && attempt < 3; attempt++) {
		String retryAfter = response.getHeaders().getFirst(HttpHeaders.RETRY_AFTER);
		long seconds = (retryAfter != null && retryAfter.matches("\\d{1,4}")) ? Long.parseLong(retryAfter) : 1;
		try {
			Thread.sleep(1000 * Math.max(1, Math.min(seconds, 5)));
		}
		catch (InterruptedException ex) {
			Thread.currentThread().interrupt();
			break;
		}
		response = send(method, path, type, body, idempotencyKey, uriVariables);
	}
	return new Answer<>(response.getStatusCode().value(), response.getBody());
}

private <T> ResponseEntity<T> send(HttpMethod method, String path, Class<T> type, Object body, String idempotencyKey, Object[] uriVariables) {
	RestClient.RequestBodySpec request = this.http.method(method).uri(path, uriVariables).accept(MediaType.APPLICATION_JSON);
	if (body != null) {
		request.contentType(MediaType.APPLICATION_JSON).body(body);
	}
	if (idempotencyKey != null) {
		request.header("Idempotency-Key", idempotencyKey);
	}
	// retrieve() throws on 4xx and 5xx. exchange() hands the refusal back: the status is here, and the error envelope is the body.
	return request.exchange((sent, answer) -> ResponseEntity.status(answer.getStatusCode()).headers(answer.getHeaders()).body(answer.bodyTo(type)));
}
```

**Confirm method**

src/main/java/com/example/quickstart/SignupController.java (excerpt)

```java
// Step 6: confirm the record with the secret key before the account exists.
@PostMapping("/api/signup/confirm")
@ResponseBody
ResponseEntity<Map<String, Object>> confirm(@RequestBody ConfirmRequest body, HttpServletRequest request) {
	Answer<SignatureRecord> answer = this.esc.call(HttpMethod.GET, "/records/{id}", SignatureRecord.class, null, null,
			body.recordId() != null ? body.recordId() : "missing");
	SignatureRecord record = answer.body();
	HttpSession session = request.getSession(false); // false: a caller without a session does not get a new one

	boolean confirmed = answer.status() == 200 && session != null
			&& SEALED.contains(record.status())
			&& Boolean.valueOf(this.live).equals(record.livemode())
			&& record.signer() != null && record.signer().externalId().equals(session.getAttribute("signerId"))
			&& record.documents().stream().map(PinnedDocument::versionId).sorted().toList().equals(session.getAttribute("versionIds"));

	if (!confirmed) {
		log.info("refused");
		return ResponseEntity.status(HttpStatus.CONFLICT).body(Map.of("confirmed", false));
	}
	log.info("confirmed {} ({})", record.id(), record.status());
	// Only now create the account, and store record.id() and the record's receipt with it.
	return ResponseEntity.ok(Map.of("confirmed", true, "recordId", record.id()));
}
```

**Properties**

`src/main/resources/application.properties`

```
# src/main/resources/application.properties
# The key is not in this file. Spring Boot binds the environment variable ESIGNCOMPLY_API_KEY
# to the property esigncomply.api.key, and the other ESIGNCOMPLY_ variables the same way.

# Timeouts for the calls to the API.
spring.http.clients.connect-timeout=5s
spring.http.clients.read-timeout=10s

# The session cookie. Tomcat sets no SameSite attribute unless you ask for one.
server.servlet.session.cookie.same-site=lax
server.servlet.session.cookie.secure=${esigncomply.live:false}
```

Integrate with Spring Boot

## How do you integrate Esign Comply with Spring Boot?

In Spring Boot the integration is one `@Controller` and one component around `RestClient`, built from the `RestClient.Builder` that Spring Boot provides. Records with `@JsonNaming` read the API's snake_case fields, the environment variable `ESIGNCOMPLY_API_KEY` is bound to the property `esigncomply.api.key`, and the `HttpSession` keeps the pinned versions on the server.

Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run".

Source: [spring.io, Spring Boot](https://spring.io/projects/spring-boot), read on November 26, 2026.

[Spring Boot quickstart](https://esigncomply.com/docs/quickstart/spring-boot) · [All stacks](https://esigncomply.com/stacks)

Where each part lives in Spring Boot

- **Session method** · `src/main/java/com/example/quickstart/SignupController.java`
- **The API call** · `src/main/java/com/example/quickstart/EsignComply.java`
- **Confirm method** · `src/main/java/com/example/quickstart/SignupController.java`
- **Properties** · `src/main/resources/application.properties`

Run on 2026-11-26 with Spring Boot 4.2.0 (Spring Framework 7.1.0, Tomcat 11.0.27, Jackson 3.1.8) on Java 25.0.5.1 with Maven 3.10.2, RestClient on the JDK HttpClient and no Esign Comply artifact, under mvn spring-boot:run and as the packaged jar (in the official Maven container image), with the browser SDK script build and the conformance check from esigncomply 1.0.4, against the API in test mode. The test API ran on this machine over plain http, where the JDK HttpClient asks the server to upgrade to HTTP/2 and that server closes the connection, so the app's calls went through a local HTTP/1.1 pass-through with the source unchanged. Its calls over https, where HTTP/2 is negotiated differently, were not run.

Copy-paste prompt

## What prompt adds Esign Comply clickwrap to a Spring Boot app?

Paste this into Cursor, Claude Code or the AI coding tool that is open on your project. It names the packages that exist, where the secret key goes in Spring Boot, what to build and what never to do, and it ends with the rules block for your project.

The rules block lives at [/rules.md](https://esigncomply.com/rules.md). Added to your project's instruction file, it makes every later session build signing and acceptance flows the same way. The [prompt generator](https://esigncomply.com/product/prompt-generator) writes the long version, with your own document and profile IDs.

[Pages for each AI tool](https://esigncomply.com/build)

Prompt: Esign Comply clickwrap in Spring Boot

```
Add Esign Comply clickwrap to my Spring Boot app: a signup form where the user accepts the Terms of Service and the Privacy Notice with a checkbox and a button.

Read these first and follow them exactly. If something conflicts with existing code, or you are unsure how to implement a step, stop and ask. Do not invent API methods, packages or legal wording.
- https://esigncomply.com/docs/quickstart/spring-boot.md (the steps and the tested code for Spring Boot)
- https://esigncomply.com/setup.md (the order of API calls)
- https://esigncomply.com/auth.md (how to handle the keys)

Spring Boot facts
- There is no Esign Comply package for Java. Do not install or invent one. The server calls the REST API at https://esigncomply.com/v1 with Authorization: Bearer and the secret key, using a RestClient built from the RestClient.Builder that Spring Boot provides.
- The browser SDK is a script tag: https://esigncomply.com/sdk/v1/esigncomply.js. It defines the global EsignComply.
- The secret key is in the environment variable ESIGNCOMPLY_API_KEY, which Spring Boot binds to the property esigncomply.api.key. Spring Boot does not read .env files on its own. Never write the key into application.properties. Never print the key.
- retrieve() throws on 4xx and 5xx. Use exchange() and read the status before you read the record.
- The API's JSON is snake_case. Put @JsonNaming(SnakeCaseStrategy.class) on the records that read it. Do not set spring.jackson.property-naming-strategy for the whole app: it renames the app's own JSON too. On Spring Boot 4 the Jackson imports are tools.jackson.databind.
- Keep the signer ID and the pinned version IDs in the HttpSession, or in the store the project already has. Read it with request.getSession(false) in the confirm route. Set server.servlet.session.cookie.same-site.
- Return the document HTML with the content type text/html, unmodified. In a Thymeleaf template that is th:utext: th:text escapes it.
- Without Spring Security there is no CSRF check. If the project has Spring Security, send its CSRF token with both POST requests.
- The page is on screen before the script has a session: render the checkbox disabled and enable it when observeAssent has resolved.

Build
1. Verify the key: GET /v1/usage with ESIGNCOMPLY_API_KEY. Stop if it fails.
2. Register the Terms of Service and the Privacy Notice as documents and publish one version of each from the documents in this project. If the project has none, register short sample documents and say so in your report. Never write or change the wording of the real documents. Create a profile: jurisdictions ["US-FED"], method "checkbox", assurance_level "L1".
3. Controller method for POST /api/ceremony: call POST /v1/sessions with an Idempotency-Key, save the signer ID and the pinned version IDs in the HttpSession, and return only clientToken, apiUrl and documents.
4. Controller method for GET /legal/{slug}: render the html from GET /v1/documents/{id}/versions/{version_id}/content inside <article data-esc-document>, unmodified.
5. Browser: EsignComply.attach({ clientToken, apiUrl }), presentDocument for each link, observeAssent({ region, checkbox, submit }), then complete() from the user's real click.
6. Controller method for POST /api/signup/confirm: call GET /v1/records/{id} and require: status is "recorded", "timestamped" or "anchored"; livemode is as expected; the signer ID and version IDs equal the ones in the HttpSession. Only then create the account.

Never
- Never pre-check the box, auto-submit, or call .click() on the user's behalf.
- Never use "By continuing" or "By clicking below" wording. The notice names the button by its label and each document by its registered name.
- Never put the secret key, or any call that uses it, in code that reaches the browser.
- Never show "signed" or "accepted" before the server has confirmed the record.
- Never fall back to an acceptance with no record when a session is refused.

Check before you report success
- Run: npx esigncomply check --url http://localhost:8080/signup --callback http://localhost:8080/api/signup/confirm
  Fix every finding marked "block". List every finding marked "warn".
- Report the files you created or changed, anything you did not implement and why, and the conformance summary.

Then add the rules block to this project's instruction file: https://esigncomply.com/rules.md
```

3 things to watch

## What goes wrong when you add e-signatures in Spring Boot?

These are specific to Spring Boot. Each one was seen while the quickstart's code was run, or is in Spring Boot's own documentation.

- **RestClient.retrieve() throws on a refusal from the API**

  Spring's documentation says `RestClient` throws a subclass of `RestClientException` when retrieving a response with a 4xx or 5xx status code. In the test on Spring Boot 4.2.0 a made-up record ID threw `HttpClientErrorException$NotFound`. The quickstart calls `exchange()`, which handed back status `404` and the error envelope, so the confirm method answers `409` and not `500`.

  Source: [Spring Framework reference, REST Clients](https://docs.spring.io/spring-framework/reference/integration/rest-clients.html), read on November 26, 2026.

- **Jackson leaves snake_case fields null, and a global strategy renames your own JSON**

  Spring Boot's documentation says Jackson 3 is the preferred and default library. In the test it read the API's answer into a record with `clientToken` left `null` and nothing thrown. With `spring.jackson.property-naming-strategy=SNAKE_CASE` for the whole app, the confirm route stopped reading `recordId` from the page. The quickstart puts `@JsonNaming(SnakeCaseStrategy.class)` on the records that read the API.

  Source: [Spring Boot reference, JSON](https://docs.spring.io/spring-boot/reference/features/json.html), read on November 26, 2026.

- **The JSESSIONID cookie has no SameSite attribute until you set one**

  In the test on Tomcat 11.0.27 the session cookie was `JSESSIONID`, with `Path=/` and `HttpOnly` and nothing else. With `server.servlet.session.cookie.same-site=lax` in `application.properties` it carried `SameSite=Lax`. A method parameter of type `HttpSession` gave a new session to a caller with no cookie, so the confirm method calls `getSession(false)`.

## Where are the Spring Boot quickstart and the API reference?

Start with the quickstart: it carries every file this page excerpts, in the order you write them.

- Quickstart

  **[Spring Boot quickstart](https://esigncomply.com/docs/quickstart/spring-boot)**

  Step by step, from install to your first sealed test record, with every file and the output of each step.

- Reference

  **[API reference](https://esigncomply.com/docs/api)**

  Every endpoint, field and error code. Sessions, records and documents are the three this page uses.

- Guide

  **[Server confirmation](https://esigncomply.com/docs/guides/server-confirmation)**

  The one place access is granted: what to compare, and the webhook that backs the check up.

Verifiable

## What does Esign Comply record for a signature in Spring Boot?

The same record on every stack and platform. Your Spring Boot code creates the session and confirms the record, and the browser SDK reports what happened on the page. Esign Comply seals the result where your code cannot change it. The record itself is described on [Evidence and verification](https://esigncomply.com/product/evidence).

- **Observed and asserted fields**

  Every field is tagged. Observed is what the browser SDK and the API saw: the box unchecked at load, the tick from a trusted user event, the notice text, the terms version by hash, the server time. Asserted is what your app said, such as the user's email.

- **A signed receipt**

  `complete()` returns a receipt signed with ES256, using keys you do not hold. Your server stores it next to the user, and `GET /v1/records/{id}/receipt` returns it again.

- **An external timestamp**

  An outside authority timestamps the hash of every live record (RFC 3161), so the time on the record does not rest on your clock or on ours.

- **An offline verifier**

  Each record has an evidence report (PDF) and an evidence package (ZIP). Anyone you send the package to checks the acceptance with the open-source `esigncomply-verify`, without an account.

[How sealing and verification work](https://esigncomply.com/product/evidence) · [Observed and asserted, in the docs](https://esigncomply.com/docs/concepts/observed-and-asserted) · [The offline verifier](https://esigncomply.com/docs/sdk/verify)

Record

`rec_Z4m8`

simple · L1

Recorded

Written durably, receipt signed with ES256

Timestamped

External RFC 3161 token over the record hash

Anchored

Public anchor pending

Checkbox changed by a trusted user event · observed

Terms of Service, version dv_3kT9 · observed

Server time 2026-11-21T15:03:20.291Z · observed

Signer email dana@example.org · asserted

record_hash sha256:5be7… · example record

## Questions about e-signatures in Spring Boot

### Is there an Esign Comply SDK for Spring Boot?

No. The server SDK exists for Node.js only, and there is no Maven artifact. A Spring Boot app calls the REST API directly with the secret key, and the quickstart does it with `RestClient` and Jackson. The browser side is the same SDK as on every stack, loaded from a script tag.

### Where do I create the session in Spring Boot?

In a controller method mapped with `@PostMapping` to `/api/ceremony`, with a `POST` to `/v1/sessions` that carries the secret key and an `Idempotency-Key`. The method saves the pinned versions in the `HttpSession` and returns only the client token, the API URL and the documents.

### How does ESIGNCOMPLY_API_KEY become a Spring Boot property?

By its name. Spring Boot binds the environment variable to the property `esigncomply.api.key`, which the quickstart reads with `@Value`. In the test the variable also answered to `esigncomply.api-key` and not to `esigncomply.apiKey`. Spring Boot did not read `.env`: with the variables missing, the session route answered `502` with `missing_api_key`.

### Do the POST routes need a CSRF token without Spring Security?

No. CSRF protection belongs to Spring Security, and the quickstart does not add it. In the test a `POST` with no token and the `Origin` of another site reached the confirm method, which refused the made-up record with `409`. If your app has Spring Security, send its token with both requests.

### Which property makes Spring Boot trust X-Forwarded-Proto?

`server.request.header.forwarded.strategy`, set to `web-server` or `framework`. In the test on Spring Boot 4.2.0 a request with `X-Forwarded-Proto: https` was seen as `http` by default and as `https` with either value. The older name `server.forward-headers-strategy` still worked, and the metadata of 4.2.0 marks it deprecated.

### Other stacks

- [Go](https://esigncomply.com/go)
- [Node.js](https://esigncomply.com/nodejs)
- [Django](https://esigncomply.com/django)

### Platforms used with Spring Boot

- [Google Cloud Run](https://esigncomply.com/google-cloud-run)
- [Railway](https://esigncomply.com/railway)
- [Render](https://esigncomply.com/render)

[All stacks](https://esigncomply.com/stacks) · [All platforms](https://esigncomply.com/platforms) · [Clickwrap API](https://esigncomply.com/clickwrap) · [E-signature API](https://esigncomply.com/sign)

## Add one controller to your Spring Boot app. Leave the record to us.

[Get an API key](https://esigncomply.com/signup) · [Read the docs](https://esigncomply.com/docs/quickstart/spring-boot)

Free plan: 10 live signatures a month and a full test mode. No card required.

Spring Boot is a trademark of its owner. Esign Comply is not affiliated with it. What this page says about Spring Boot is from Spring Boot's documentation or from a test run, as marked, on November 26, 2026. `/spring-boot.md` is this page as Markdown.

---

Every page on esigncomply.com has a Markdown version at the same URL plus `.md` (the home page is `https://esigncomply.com/index.md`). https://esigncomply.com/llms.txt lists them.

---

Esign Comply is the e-signature API and clickwrap API for developers who build their own signing flow in their own UI: it supplies the ceremony rules as a generated prompt for AI coding tools, records events in direct browser ceremonies, and seals independent, verifiable evidence.
