Docs/Integrations/Java / Spring Boot

Java / Spring Boot Integration

Drop NxtOne into a Spring Boot service with a single dependency.

The NxtOne Java SDK runs inside your JVM and sends behavioral events straight to the NxtOne platform over HTTPS — there is no separate process, container, or daemon to run. On Spring Boot, the starter attaches the SDK for you when the application starts; any other JVM application calls Nxtone.attach() once at the top of main().

1. Quickstart

1

Add the dependency

Add nxtone-agent-spring-boot-starter to your build, with nxtone.version (Maven) or nxtoneVersion (Gradle) set to the latest release:

Maven (pom.xml)
xml
<dependency> <groupId>ai.nxtone</groupId> <artifactId>nxtone-agent-spring-boot-starter</artifactId> <version>${nxtone.version}</version> </dependency>
Gradle (build.gradle)
gradle
dependencies { // set nxtoneVersion in gradle.properties to the latest release implementation "ai.nxtone:nxtone-agent-spring-boot-starter:${nxtoneVersion}" }
2

Configure properties

Add NxtOne configuration to your application.yml or application.properties:

yaml
nxtone: api-key: ${NXTONE_API_KEY} project-id: my-spring-service # Comma-separated CLASS / PACKAGE prefixes to leave uninstrumented. # These are matched against fully-qualified class names, NOT URL paths. exclude: com.acme.generated,com.acme.internal.legacy

Or configure entirely through environment variables (recommended for containers):

bash
export NXTONE_API_KEY="<your-api-key>" export NXTONE_PROJECT_ID="my-spring-service"
3

Run your application

No annotations, no main() changes, no -javaagent flag, and no JVM arguments (on JDK 17–20). Adding the dependency is the entire integration. Confirm it in the startup output on stderr:

text
nxtone: agent attached (pid=12345) nxtone: application ready — capture window open

Both lines must appear: the first confirms the SDK attached, the second that capture is open.

2. Without Spring Boot

Any other JVM application uses the core artifact, ai.nxtone:nxtone-agent, and calls Nxtone.attach() as the first line of main():

xml
<dependency> <groupId>ai.nxtone</groupId> <artifactId>nxtone-agent</artifactId> <version>${nxtone.version}</version> </dependency>
java
public static void main(String[] args) { Nxtone.attach(); // must be the first line // ...start your application }

If you ship a shaded uber-JAR, set NXTONE_AGENT_JAR to the path of the SDK JAR (for example /path/nxtone-agent.jar). Loading that JAR with -javaagent also works, but it is optional — never required.

3. Requirements & compatibility

RequirementSupportedDetail
Java / JDK17+The starter and Spring adapter are compiled at maven.compiler.release=17. Java 8 and 11 cannot use this starter. Spring Boot 3.0 requires Java 17+ as a minimum baseline.
JDK 21+Supported with one flagAdd -XX:+EnableDynamicAgentLoading — see Troubleshooting.
Spring Boot3.xVerified against Spring Boot 3.3.7. Boot 2.7.x is not supported because the adapter uses jakarta.servlet exclusively.
Framework supportMVC + WebFluxSpring Web MVC via NxtOneHandlerInterceptor; WebFlux via NxtOneWebFluxAutoConfiguration. Outbound propagation for RestTemplate, WebClient, and OpenFeign.
Build toolsMaven, GradleStandard Maven and Gradle builds.
FilesystemWritable temp directoryAt startup the starter copies its JAR into the JVM's temp directory (/tmp by default); if it can't, it logs nxtone: agent attach failed and the app runs uninstrumented. With a read-only root filesystem, mount an emptyDir or tmpfs at /tmp.

4. Configuration reference

Supported, user-facing configuration keys. Configure them in application.yml or through environment variables:

YAML keyEnv variableDefaultDescription
nxtone.api-keyNXTONE_API_KEYrequiredAPI key from the NxtOne dashboard. If absent, the SDK runs as a no-op: it prints a hint to stderr, sends nothing, and never fails your app.
nxtone.project-idNXTONE_PROJECT_IDunknownName or ID of your service. Always set it explicitly so each service gets its own project.
nxtone.excludeNXTONE_EXCLUDEemptyClass/package name prefixes to leave uninstrumented (matched with startsWith against fully-qualified class names, not URL paths).

Outside Spring, the SDK reads the same settings from a properties file, looked up in this order: -Dnxtone.config, $NXTONE_CONFIG_FILE, ~/.nxtone/config.properties, ./nxtone.properties.

Internal SDK tuning knobs

Read by the SDK for buffer management and batching:

Env variableDefaultEffect
NXTONE_BATCH_SIZE100Events per outbound HTTP batch
NXTONE_FLUSH_INTERVAL_MS500Background flush timer interval in milliseconds
NXTONE_MAX_QUEUE_SIZE10,000Maximum event queue capacity (bounded in event count)
NXTONE_MAX_BATCH_BYTES512 KiBOutbound batch byte limit
NXTONE_MAX_RETRIES3Max retry attempts with exponential backoff (capped at 30s) before a batch is dropped or spooled to disk
NXTONE_REQUEST_TIMEOUT_MS10,000Read timeout for outbound requests (connect timeout capped at 5,000ms)
NXTONE_SHUTDOWN_TIMEOUT_SECONDS5Total wall-clock budget for the flush at JVM shutdown
NXTONE_SPOOL_DIRunsetIf set, batches that exhaust their retries are written here instead of dropped. Off by default.

5. How it works

The Spring Boot starter registers two entries in META-INF/spring.factories:

  • EnvironmentPostProcessor → NxtOneAgentAutoAttach: mirrors nxtone.* config into system properties, then self-attaches the SDK using ByteBuddy's HotSpot attach protocol at LOWEST_PRECEDENCE.
  • ApplicationListener → NxtOneReadyListener: opens the capture window at ApplicationReadyEvent.

Events are batched in memory and sent over HTTPS (443) to api.nxtone.ai; large values go to Amazon S3 through presigned URLs. The SDK opens no listening ports, and it flushes what is still queued when the JVM shuts down.

Execution overhead and memory bounds
  • Startup time delta: ~+18% (+1.19s median) during class-loading weaving, measured on a 208-source-file benchmark.
  • Requests are never blocked on I/O: all network I/O is owned by a dedicated daemon shipper thread. Queue overflow parks application threads for a bounded max of 500µs before dropping.
  • Dependency isolation: SDK dependencies (Jackson, slf4j, JavaParser, ASM) are shaded under ai.nxtone.agent.shaded.* to prevent version collisions.

6. Security & privacy controls

  • Request headers never collected: Authorization, Cookie, and Set-Cookie are never read or transmitted.
  • User-Agent hashed: User-Agent headers are hashed into anonymous IDs, never stored raw.
  • No code execution during reflective capture: values are read via reflective field access only — no getters, toString(), serializers, or lazy initializers are ever invoked.
  • Automatic safety exclusions: @Configuration classes, @Repository interfaces, and @Transactional methods are skipped automatically to avoid corrupting Spring Security filter chains or connection pools.

7. Troubleshooting & diagnostics

Check the SDK's state in the stderr startup output:

Stderr output lineMeaning
nxtone: agent attached (pid=...)Self-attach succeeded.
nxtone: application ready — capture window openCapture is live. Both lines are required for full capture.
nxtone: agent attach failed (...)Attach failed. The application runs normally, without capture.
nxtone: could not open capture window at app-readyAttached, but line/variable capture failed to open.
nxtone: no api-key configured - running in NO-OP modeNo key found. The SDK runs as a zero-cost no-op.
JDK 21+ dynamic agent loading. JDK 21 restricts dynamic self-attach (JEP 451). On JDK 21+, add the JVM flag -XX:+EnableDynamicAgentLoading. If ByteBuddy transitive versions conflict with Mockito, exclude net.bytebuddy:byte-buddy-agent in your build file.

For containers, see Docker and Kubernetes; for anything else, work through Troubleshooting.