Add e-signatures and clickwrap to 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.
No Esign Comply artifact: spring-boot-starter-webmvc and spring-boot-starter-restclient
Spring Boot quickstartFree plan: 10 live signatures a month and a full test mode. No card required.
Last updated
// 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())); }
/** 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))); }
// 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())); }
# 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}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, read on .- Session methodsrc/main/java/com/example/quickstart/SignupController.java
- The API callsrc/main/java/com/example/quickstart/EsignComply.java
- Confirm methodsrc/main/java/com/example/quickstart/SignupController.java
- Propertiessrc/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.
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. Added to your project's instruction file, it makes every later session build signing and acceptance flows the same way. The prompt generator writes the long version, with your own document and profile IDs.
Pages for each AI toolAdd 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.mdWhat 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.
- 01
RestClient.retrieve() throws on a refusal from the API
Spring's documentation says
Source: Spring Framework reference, REST Clients, read on .RestClientthrows a subclass ofRestClientExceptionwhen retrieving a response with a 4xx or 5xx status code. In the test on Spring Boot 4.2.0 a made-up record ID threwHttpClientErrorException$NotFound. The quickstart callsexchange(), which handed back status404and the error envelope, so the confirm method answers409and not500. - 02
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
Source: Spring Boot reference, JSON, read on .clientTokenleftnulland nothing thrown. Withspring.jackson.property-naming-strategy=SNAKE_CASEfor the whole app, the confirm route stopped readingrecordIdfrom the page. The quickstart puts@JsonNaming(SnakeCaseStrategy.class)on the records that read the API. - 03
The JSESSIONID cookie has no SameSite attribute until you set one
In the test on Tomcat 11.0.27 the session cookie was
JSESSIONID, withPath=/andHttpOnlyand nothing else. Withserver.servlet.session.cookie.same-site=laxinapplication.propertiesit carriedSameSite=Lax. A method parameter of typeHttpSessiongave a new session to a caller with no cookie, so the confirm method callsgetSession(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.
- QuickstartSpring Boot quickstartStep by step, from install to your first sealed test record, with every file and the output of each step.Open
- ReferenceAPI referenceEvery endpoint, field and error code. Sessions, records and documents are the three this page uses.Open
- GuideServer confirmationThe one place access is granted: what to compare, and the webhook that backs the check up.Open
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.
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, andGET /v1returns it again./records /{id} /receipt 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.
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, with a POST to /v1 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.
Add one controller to your Spring Boot app. Leave the record to us.
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 . /spring-boot.md is this page as Markdown.