Installation Guide

Install the signature-verified CLI, then configure the Spring project with Quick or Custom. The CLI applies a consistent set of selected code, configuration, and infrastructure changes and tracks only the state it owns.

CLI installation and project initialization

Install the signed CLI, run it from the Spring Boot project, and select Quick or Custom. Every path shows the planned files, dependencies, infrastructure, and Docker action before mutation.

Step 1 - Install the CLI

Linux / macOS
curl -fsSL https://install.ctxa.ai/install.sh | sh
Windows PowerShell 5.1+
irm https://install.ctxa.ai/install.ps1 | iex

The installer verifies the signed manifest and SHA-256. It installs the executable only; it does not alter a Spring project.

Step 2 - Diagnose and initialize

Shell
cd your-spring-project
contexa init --check   # optional, read-only
contexa init
SelectionExact behavior
QuickMerge integration, FULL security ownership mode, SHADOW enforcement, one selected provider, optional automatic annotation, Standalone infrastructure, and Docker startup when available.
CustomChoose integration, security ownership, enforcement, one or more providers, infrastructure, output paths, and whether Docker starts.

contexa init --yes means Quick with Ollama, automatic @EnableAISecurity, Standalone PostgreSQL/Ollama infrastructure, and Docker startup when available. It is not a starter-only command. Add --no-docker when you want Compose files without container startup.

Step 3 - Understand generated state

  • Merge: updates the build, writes application-contexa.yml, and changes the main source only when automatic annotation was selected. The host application.yml is preserved.
  • Standalone integration: writes Contexa YAML and a Gradle/Maven fragment in a separate directory. Host build, YAML, and source remain unchanged; the user wires the generated fragment.
  • Standalone infrastructure: PostgreSQL plus Ollama only when Ollama is among the selected providers.
  • Distributed infrastructure: PostgreSQL, Redis, ZooKeeper, Kafka, plus Ollama only when selected.
  • Skip infrastructure: no Compose file and no Docker mutation.

Step 4 - Run, inspect, and reset

Shell
./gradlew bootRun
contexa status
contexa reset

reset restores only CLI-owned state recorded by the manifest. It does not silently overwrite a user-modified file or remove unrelated infrastructure.

Manual dependency-only — Adding the Starter directly without @EnableAISecurity remains a valid no-impact path, but it is separate from CLI Quick initialization.

Legacy System Integration (SANDBOX Mode)

If the project already owns authentication and authorization, use SANDBOX/HOST_OWNED. Contexa receives the authenticated host principal through the bridge and runs its Zero Trust runtime independently.

Java
@EnableAISecurity(
    mode = SecurityMode.SANDBOX,
    authObjectLocation = AuthObjectLocation.SESSION,
    authObjectAttribute = "loginUser"  // your legacy session attribute name
)
@SpringBootApplication
public class LegacyApplication { }

Host-owned security —SANDBOX uses the HOST_OWNED runtime contract. Contexa receives the authenticated principal through the bridge and does not replace or write the host application's SecurityContext. It evaluates only explicitly selected Contexa resources.

Contexa CLI Command Reference

Detailed overview of the primary commands provided by the Contexa CLI. You can execute them in your terminal via contexa <command> [options].

Command Description Key Options
init Applies a consistent set of Starter, provider, @EnableAISecurity, application-contexa.yml, and infrastructure Compose changes from the Quick or Custom selection. Quick defaults to Ollama, source annotation, and Standalone infrastructure. --yes: Apply Quick defaults without prompts
--quick: Select the Quick setup
--provider openai|anthropic|ollama: Select providers (comma-separated values supported)
--include-ollama: Include Ollama alongside another provider
--auto-annotate: Add @EnableAISecurity to Merge source
--security-mode sandbox|full: Select HOST_OWNED or CONTEXA_OWNED
--merge / --standalone: Select host integration mode
--standalone-dir <path>: Set the Standalone application directory
--distributed: Select PostgreSQL, Redis, ZooKeeper, and Kafka infrastructure
--infra-dir <path>: Set the infrastructure file directory
--no-docker: Generate Compose without starting containers
--simulate: Configure the isolated ctxa-sim environment
--dir <path>: Set the target project
--force: Re-run when Contexa is already detected
--check: Run preflight checks without changes
--enable-ai-security: Compatibility option; current Quick and Custom setups already configure AI security
reset Reverts only CLI-recorded changes and/or removes selected Contexa-owned infrastructure. User edits after init are not overwritten silently. --dir <path>: Target project directory (defaults to current dir)
-s, --simulate: Reset the isolated simulation environment and ctxa-sim containers/volumes
-y, --yes: Skip the reset confirmation. Manifest ownership and conflict checks still apply.
simulate Manages the lifecycle of the isolated simulation container stack (ctxa-sim-*) (subcommands: up, down, reset, logs, ps). up: Start simulation containers
down: Stop simulation containers
reset: Reset simulation database volumes (restarts as a clean, empty database)
logs: View container logs
ps: Check container running status
mode Dynamically switches the Zero Trust enforcement mode between SHADOW and ENFORCE. --enforce, -e: Block threats in real-time immediately
--shadow, -s: Monitor and log threat events without blocking
doctor Runs diagnostics for the selected path. Docker is checked whenever the selected setup asks the CLI to start local infrastructure. N/A
status Reports whether the project is not initialized, only has a user-owned Starter dependency, or is managed by a Contexa installation manifest. N/A
scan Scans project source files for proper integration of @EnableAISecurity and dependencies. N/A

Prerequisites

Required for both CLI and manual installation:

Requirement Version Purpose
Java 17+ Runtime (configured via Gradle toolchain)
Spring Boot 3.5.4 validation baseline Spring Boot 3.x target. 4.x is not supported.
Docker Supported current release Optional. Used only for CLI-managed local infrastructure, simulation, or distributed demo stacks

Quick versus Distributed. Quick configures Standalone PostgreSQL and the selected Ollama service. Select Custom or contexa init --distributed only when you need PostgreSQL, Redis, ZooKeeper, and Kafka together.

Manual Installation

If you prefer not to use the CLI, use the stable artifacts from Maven Central. A normal consumer build needs only mavenCentral().

1. Add Dependency

Gradle (Groovy)
dependencies {
    implementation 'ai.ctxa:spring-boot-starter-contexa:0.1.0'
}
Maven
<dependency>
    <groupId>ai.ctxa</groupId>
    <artifactId>spring-boot-starter-contexa</artifactId>
    <version>0.1.0</version>
</dependency>

2. Configure only selected features

The Starter provides common defaults through auto-configuration. Manual dependency-only integration needs no provider, database, or Docker configuration. Add those items only when you activate the corresponding feature.

Feature When needed Typical requirement
Dedicated Contexa DB Identity, IAM, audit, vector evidence, or AI security persistence PostgreSQL with pgvector when vector evidence is enabled
AI security You declare @EnableAISecurity and protect resources with @Protectable One LLM provider starter and matching Contexa provider settings
Local Ollama You choose Ollama as the provider Ollama runtime and the selected chat/embedding models
Distributed mode You run multiple application instances or an enterprise demo Redis and Kafka, configured under contexa.infrastructure.*

Troubleshooting

Using Diagnostic Tools — If you encounter any issues during setup or execution, run contexa doctor in your terminal to check your environment. For a catalog of common errors and OS-specific fixes, visit the dedicated Troubleshooting Guide.

@EnableAISecurity startup error guide

You may hit the following errors if you add @EnableAISecurity to a manual dependency-only integration, select external infrastructure in Custom but omit required provider or database settings, or remove generated configuration. Quick generates the selected provider dependency, source annotation, and Standalone database configuration together. Each error below shows the exact message, root cause, and fix.

Error 1 — contexa.datasource.url must be configured for @EnableAISecurity

Full message: java.lang.IllegalStateException: contexa.datasource.url must be configured for @EnableAISecurity. Use a dedicated Contexa database by default; sharing the application database requires explicit POC approval.

Root cause — Contexa stores security policy, sessions and the vector index in a dedicated PostgreSQL instance, isolated from your application database. When @EnableAISecurity is on, contexa.datasource.url must be set or ContexaDataSourceIsolation fails fast.

Fix — add a Contexa-owned datasource block to your application.yml:

application.yml
contexa:
  datasource:
    url: jdbc:postgresql://localhost:5432/contexa
    username: ${CONTEXA_DB_USERNAME:contexa}
    password: ${CONTEXA_DB_PASSWORD:contexa1234!@#}
    driver-class-name: org.postgresql.Driver
    isolation:
      contexa-owned-application: true

You may share the application's PostgreSQL instance via a separate schema if your operations team explicitly approves it. The default is a separate database (recommended).

Error 2 — No Spring AI ChatModel is configured for CONTEXA

Full message: No Spring AI ChatModel is configured for CONTEXA. Add at least one Spring AI chat provider starter to your application dependencies (for example org.springframework.ai:spring-ai-starter-model-openai, org.springframework.ai:spring-ai-starter-model-anthropic, or org.springframework.ai:spring-ai-starter-model-ollama), then configure the matching provider under spring.ai.*

Root cause — Contexa's tiered LLM auto-configuration (CoreLLMTieredAutoConfiguration) requires a ChatModel bean, but no Spring AI provider starter is on the classpath. spring-boot-starter-contexa intentionally does not pull a ChatModel starter as a transitive dependency — the choice of provider (Ollama / OpenAI / Anthropic) is yours.

Fix — add at least one provider starter to your build and configure the matching contexa.llm.* block (Contexa bypasses Spring AI's default autoconfiguration and manages model creation via its dedicated contexa.llm namespace):

build.gradle (Ollama example)
dependencies {
    implementation 'ai.ctxa:spring-boot-starter-contexa:0.1.0'
    // Add only when you declare @EnableAISecurity (one provider or more)
    implementation 'org.springframework.ai:spring-ai-starter-model-ollama'
}
application.yml (Ollama example)
contexa:
  llm:
    selection:
      chat:
        mode: dynamic-priority
        priority: ollama,openai,anthropic
    chat:
      ollama:
        baseUrl: ${CONTEXA_CHAT_OLLAMA_BASE_URL:http://127.0.0.1:11434}
        model: ${CONTEXA_CHAT_OLLAMA_MODEL:qwen2.5:7b}
        keepAlive: ${CONTEXA_OLLAMA_CHAT_KEEP_ALIVE:30m}
    embedding:
      ollama:
        dedicatedRuntimeEnabled: false
        model: ${CONTEXA_EMBEDDING_OLLAMA_MODEL:mxbai-embed-large}
        dimensions: ${CONTEXA_EMBEDDING_OLLAMA_DIMENSIONS:1024}

For OpenAI or Anthropic, swap in spring-ai-starter-model-openai / spring-ai-starter-model-anthropic and set the API key under contexa.llm.openai.* / contexa.llm.anthropic.*.

Error 3 — rag-vector capability unresolved / SecurityDecisionPostProcessor not created

Full message (excerpt): [ContexaCapability] rag-vector ... Resolve rag-vector first; SecurityDecisionPostProcessor is created only after UnifiedVectorService is available.

Root cause — the @EnableAISecurity decision post-processor (SecurityDecisionPostProcessor) depends on UnifiedVectorService, which in turn requires a Spring AI VectorStore bean. Without the pgvector vector-store starter on the classpath, the rag-vector capability stays unresolved and the downstream bean tree never wires up.

Fix — add the pgvector vector-store starter and configure contexa.vectorstore.pgvector.*. Use the pgvector/pgvector:pg16 Docker image so the vector extension is enabled out of the box.

build.gradle
dependencies {
    implementation 'org.springframework.ai:spring-ai-starter-vector-store-pgvector'
}
application.yml
contexa:
  vectorstore:
    pgvector:
      dimensions: 1024
      initialize-schema: true

Why does the default path stay small? — Many applications depend on spring-boot-starter-contexa without enabling AI security. Injecting Spring AI provider and vector-store starters into every project would make ChatModel or PgVectorStore beans start against missing infrastructure. The wizard can add the selected provider path, but only after you explicitly choose AI security and confirm the file changes.

Infrastructure issues

Container name conflict — The container name "/contexa-postgres" is already in use

Full message (excerpt): Error response from daemon: Conflict. The container name "/contexa-postgres" is already in use by container "<hash>". You have to remove (or rename) that container to be able to reuse that name.

Followed by contexa-cli: × Docker start failed. Run manually: docker compose up -d

Root cause — a container with the same name (contexa-postgres, contexa-ollama, ...) already exists on the host. The Docker daemon does not allow two containers to share a name. Two common cases:

  • A previous contexa init run left those containers up — safe to reuse as-is.
  • Another project occupies the same name — clean it up, or switch to the isolated simulate mode.

Option 1 — keep the existing containers (recommended, preserves data)

Shell
# 1) confirm the containers are running
docker ps --filter "name=contexa-" --format "table {{.Names}}\t{{.Status}}"

# 2) leave them up and just start the app
./gradlew bootRun

Option 2 — remove and recreate (DATA LOSS WARNING)

Shell
# Stop + remove (volumes are preserved)
docker rm -f contexa-postgres contexa-ollama
# Distributed mode also needs:
docker rm -f contexa-redis contexa-zookeeper contexa-kafka

# Recreate
contexa init --distributed

Option 3 — switch to the isolated simulation mode (protects production containers)

Shell
contexa init --simulate

--simulate namespaces the containers under the ctxa-sim- prefix and shifts ports by +20000, so the simulation stack runs side-by-side with production without colliding.

Problem Solution
PostgreSQL connection refused Check Docker is running: docker ps. Verify port 5432 is not in use.
Ollama connection refused Check container: docker logs contexa-ollama. Verify port 11434.
AI model not found Pull models: docker exec contexa-ollama ollama pull qwen2.5:7b and ... pull mxbai-embed-large
vector extension missing (PostgreSQL) Use the pgvector/pgvector:pg16 image, or on an existing DB run CREATE EXTENSION IF NOT EXISTS vector; once.
Port conflicts Default ports: PostgreSQL 5432, Ollama 11434, Redis 6379, Kafka 9092
contexa init —arrow keys not working Windows: use winpty contexa init in Git Bash, or run in Windows Terminal

Need more help? —Check the Configuration Reference or visit GitHub Discussions.