Sections in this lesson

Spring Boot Configuration

Understand starters, profiles, property precedence and environment-specific secrets.

Reviewed: · Content owner: Interview Preparator

What you will learn

  • Separate dependency management from auto-configuration.
  • Select demo versus real-provider behavior explicitly.
  • Fail early when required environment values are absent.

Before you start

The flow

  1. 1.Resolve properties
  2. 2.Select profile
  3. 3.Create beans
  4. 4.Validate
  5. 5.Start

Starters and versions do different jobs

A starter brings a coherent dependency set; auto-configuration creates conditional beans when prerequisites are present. A BOM aligns dependency versions but does not create objects at runtime. The lab pins Spring Boot 4.0.5 and Spring AI 2.0.2 in Maven.

Keep default properties separate from environment-specific endpoints and credentials. Environment variables and command-line arguments can override packaged configuration; investigate the effective property source before assuming a YAML edit took effect.

Use explicit operating modes

The default demo profile provides deterministic chat and eight-dimensional fixture embeddings. The ollama profile uses real provider adapters with a separate embedding dimension. Never reuse the demo index with real embeddings: matching dimensions alone would not make vector spaces compatible.

The lab disables automatic model configuration by default and enables it in application-ollama.yml. A missing database password or demo user password fails startup. Profiles are a composition mechanism, not an authorization boundary.

Validate before accepting traffic

Use typed configuration and validation for larger settings groups. Keep local schema initialization opt-in; production migrations should run with separate privileges. Do not print secret values to diagnose configuration.

Try it

application.yml
yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
server:
address: 127.0.0.1
port: 8081
spring:
profiles:
default: demo
datasource:
url: ${DATABASE_URL:jdbc:postgresql://127.0.0.1:5438/interview}
username: ${DATABASE_USER:interview}
password: ${DATABASE_PASSWORD}
ai:
model:
chat: none
embedding: none
lab:
initialize-schema: ${INITIALIZE_SCHEMA:false}
dimensions: ${EMBEDDING_DIMENSIONS:8}
alpha-password: ${DEMO_ALPHA_PASSWORD}
beta-password: ${DEMO_BETA_PASSWORD}

examples/spring-ai-lab/src/main/resources/application.yml · 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 a BOM enable a model?

No. It manages dependency versions; starters/configuration and runtime properties determine beans.

Why separate embedding indexes by mode?

Demo and real embeddings use different representations; mixing them destroys retrieval meaning.

Where should a secret live?

In environment-specific secret delivery, never in a frontend bundle, committed YAML or diagnostic output.

Practice

Add a validated maximum question length setting and override it in a test.

Check your solution

  • Invalid settings fail startup.
  • The test proves which value wins.
  • No credential is committed.

Official references

Continue learning

Category sequence

Spring & Spring Boot

Lesson 2 / 4

Was this lesson useful?

Change notes: Phase 2: bilingual lesson with versioned executable reference.