Sections in this lesson
Spring AI: Getting Started
Run a pinned Spring Boot AI laboratory with separate fixture and Ollama modes.
Reviewed: · Content owner: Interview Preparator
What you will learn
- Identify the version and dependency boundaries.
- Start PostgreSQL and the Boot service independently from the site.
- Understand what fixture and provider tests actually prove.
Before you start
The flow
- 1.Install JDK 21+
- 2.Set environment
- 3.Start pgvector
- 4.Run Boot
- 5.Call authenticated API
The reproducible baseline
The reference application pins Java 21, Spring Boot 4.0.5 and Spring AI 2.0.2. Maven imports the Spring AI BOM, then adds the Ollama starter and pgvector store module. Keep the existing 1.0.3 ChatClient pilot as a historical, standalone example; do not mix its dependency versions into this project.
The website remains frontend-only. The lab is a separate Java application bound to 127.0.0.1:8081; it does not add a Next.js API route or put provider credentials into a browser bundle.
Start the smallest working system
From the repository root, set DATABASE_PASSWORD, DEMO_ALPHA_PASSWORD and DEMO_BETA_PASSWORD; use at least 12 characters for each demo user password. Start the database with docker compose -f examples/spring-ai-lab/compose.yml up -d. Set INITIALIZE_SCHEMA=true for a new local database, then run mvn -f examples/spring-ai-lab/pom.xml spring-boot:run.
The default demo profile needs no model download. For POST, authenticate as alpha or beta, fetch /api/csrf with a cookie jar, and submit its token header with the same session. The README includes a complete command sequence.
Move to real inference deliberately
The ollama profile uses a running Ollama service with explicitly prepared chat and embedding models. Use a separate database/index and the embedding model's actual dimension. Model tags and local resource needs are deployment choices, not quality guarantees.
mvn test runs unit and HTTP-adapter fixture tests; mvn -Pintegration verify additionally starts a real pgvector container. Neither command claims that an actual downloaded model produces good answers. Evaluate that separately before relying on the results.
Try it
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>4.0.5</version> <relativePath/> </parent> <groupId>com.interviewpreparator</groupId> <artifactId>spring-ai-lab</artifactId> <version>1.0.0</version> <properties> <java.version>21</java.version> <spring-ai.version>2.0.2</spring-ai.version> <testcontainers.version>2.0.2</testcontainers.version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.ai</groupId> <artifactId>spring-ai-bom</artifactId> <version>${spring-ai.version}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.testcontainers</groupId> <artifactId>testcontainers-bom</artifactId> <version>${testcontainers.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-webmvc</artifactId></dependency> <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-validation</artifactId></dependency> <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId></dependency> <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId></dependency> <dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-starter-model-ollama</artifactId></dependency> <dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-pgvector-store</artifactId></dependency> <dependency><groupId>org.postgresql</groupId><artifactId>postgresql</artifactId><scope>runtime</scope></dependency> <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency> <dependency><groupId>org.springframework.security</groupId><artifactId>spring-security-test</artifactId><scope>test</scope></dependency> <dependency><groupId>org.testcontainers</groupId><artifactId>testcontainers-postgresql</artifactId><scope>test</scope></dependency> </dependencies> <build> <testResources> <testResource><directory>src/test/resources</directory></testResource> <testResource><directory>../agentic-ai</directory><includes><include>scenarios.json</include></includes></testResource> </testResources> <plugins> <plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin> </plugins> </build> <profiles> <profile> <id>integration</id> <build><plugins><plugin> <groupId>org.apache.maven.plugins</groupId><artifactId>maven-failsafe-plugin</artifactId> <executions><execution><goals><goal>integration-test</goal><goal>verify</goal></goals></execution></executions> </plugin></plugins></build> </profile> </profiles></project>examples/spring-ai-lab/pom.xml · mvn -f examples/spring-ai-lab/pom.xml test. Java 21+, Spring Boot 4.0.5, Spring AI 2.0.2 where applicable. The demo uses synthetic models; live inference quality is a separate check.
Interview questions
Does adding a starter create a production AI system?
No. Data access, permissions, evaluation, limits and operations remain application responsibilities.
Why keep fixture and real-provider modes separate?
They have different guarantees and embedding representations; a deterministic test is not live inference evidence.
Which command requires Docker?
The integration Maven profile and the local database compose command. Plain unit tests do not require Docker.
Practice
Run the demo from a clean database and record the exact command, versions and first successful sourced response.
Check your solution
- Application remains loopback-only.
- Missing environment values fail early.
- Provider mode has its own index and evaluation record.
Official references
Continue learning
Category sequence
Spring AI
Lesson 1 / 7
Was this lesson useful?
Change notes: Phase 2: bilingual lesson with versioned executable reference.