Quick Start: Provision your AI models on Azure AI Foundry as code with Bicep +
azdin a few minutes — see the Azure AI Foundry Setup Guide. Authentication is keyless (Microsoft Entra ID), so there are no API keys to manage.
- Set up a Java development environment for AI applications
- Choose and configure your preferred development environment (cloud-first with Codespaces, local dev container, or full local setup)
- Test your setup by connecting to an Azure AI Foundry model
- What You'll Learn
- Introduction
- Step 1: Set Up Your Development Environment
- Step 2: Provision Azure AI Foundry
- Step 3: Test Your Setup
- Troubleshooting
- Summary
- Next Steps
This chapter will guide you through setting up a development environment. We'll use Azure AI Foundry for the models throughout this course. You provision the models as code with Bicep and the Azure Developer CLI (azd), then connect with keyless authentication (Microsoft Entra ID) — no API keys to copy or leak.
No local setup required! You can use GitHub Codespaces, which provides a full development environment in your browser, and provision Foundry from there.
We use Azure AI Foundry for this course because it's:
- Provisioned as code — one
azd updeploys the account and model deployments - Keyless — authenticate with your Azure sign-in or a managed identity
- Production-ready — the same code runs locally and in Azure
- Flexible — swap models by changing a deployment name, not your code
Note: Azure AI Foundry deployments are billed per token (pay-as-you-go). See the Azure AI Foundry setup guide for provisioning, region, and cost details.
We've created a preconfigured development container to minimize setup time and ensure you have all the necessary tools for this Generative AI for Java course. Choose your preferred development approach:
Start coding in 2 minutes - no local setup required!
- Fork this repository to your GitHub account
Note: If you want to edit the basic config please have a look at the Dev Container Configuration
- Click Code → Codespaces tab → ... → New with options...
- Use the defaults – this will select the Dev container configuration: Generative AI Java Development Environment custom devcontainer created for this course
- Click Create codespace
- Wait ~2 minutes for the environment to be ready
- Proceed to Step 2: Provision Azure AI Foundry
Benefits of Codespaces:
- No local installation required
- Works on any device with a browser
- Pre-configured with all tools and dependencies
- Free 60 hours per month for personal accounts
- Consistent environment for all learners
For developers who prefer local development with Docker
- Fork and clone this repository to your local machine
Note: If you want to edit the basic config please have a look at the Dev Container Configuration
- Install Docker Desktop and VS Code
- Install the Dev Containers extension in VS Code
- Open the repository folder in VS Code
- When prompted, click Reopen in Container (or use
Ctrl+Shift+P→ "Dev Containers: Reopen in Container") - Wait for the container to build and start
- Proceed to Step 2: Provision Azure AI Foundry
For developers with existing Java environments
Prerequisites:
- Java 21+
- Maven 3.9+
- VS Code or your preferred IDE
Steps:
- Clone this repository to your local machine
- Open the project in your IDE
- Proceed to Step 2: Provision Azure AI Foundry
Pro Tip: If you have a low-spec machine but want VS Code locally, use GitHub Codespaces! You can connect your local VS Code to a cloud-hosted Codespace for the best of both worlds.
Deploy the course's AI models to Azure AI Foundry as code. From the repository root:
cd 02-SetupDevEnvironment
azd auth login
az login
azd upazd prompts for an environment name and region, provisions an Azure AI Foundry account with gpt-4o-mini and text-embedding-3-small deployments, and writes the endpoint into the example's .env — all with keyless authentication (no API keys).
Full walkthrough: See the Azure AI Foundry Setup Guide for prerequisites, a manual (portal) alternative, region guidance, and cost/cleanup notes.
Once your Foundry models are provisioned, test the connection with the example app in 02-SetupDevEnvironment/examples/basic-chat-azure.
- Open the terminal in your development environment.
- Navigate to the example:
cd 02-SetupDevEnvironment/examples/basic-chat-azure - Make sure you're signed in (keyless auth needs a token):
az login
If you ran
azd up, the.envfile with your endpoint was already written for you. - Run the application:
mvn clean spring-boot:run
You should see a response from the gpt-4o-mini model.
The example under examples/basic-chat-azure is a Spring Boot app that uses Spring AI to connect to Azure AI Foundry with keyless authentication.
What this code does:
- Connects to Azure AI Foundry using your Azure sign-in (Microsoft Entra ID) — no API key
- Sends a prompt to the
gpt-4o-minimodel - Receives and displays the AI's response
- Validates your setup is working correctly
Key Dependency (in pom.xml):
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-azure-openai</artifactId>
</dependency>Configuration (application.yml):
spring:
ai:
azure:
openai:
# Endpoint only - no api-key. Spring AI uses DefaultAzureCredential (keyless).
endpoint: ${AZURE_OPENAI_ENDPOINT}
chat:
options:
deployment-name: ${AZURE_OPENAI_DEPLOYMENT:gpt-4o-mini}Great! You now have everything set up:
- Provisioned Azure AI Foundry models as code with Bicep +
azd - Got your Java development environment running (whether that's Codespaces, dev containers, or local)
- Connected to Azure AI Foundry with keyless authentication (Microsoft Entra ID) — no API keys
- Tested it all works with a simple example that talks to your model
Chapter 3: Core Generative AI Techniques
Having issues? Here are common problems and solutions:
-
Authentication failing (401/403)?
- Run
az login— authentication is keyless, so you must be signed in - Verify your account has the Cognitive Services OpenAI User role on the resource
- If you just provisioned, wait a minute for the role assignment to propagate
- Run
-
Maven not found?
- If using dev containers/Codespaces, Maven should be pre-installed
- For local setup, ensure Java 21+ and Maven 3.9+ are installed
- Try
mvn --versionto verify installation
-
azdnot found or provisioning fails?- Install the Azure Developer CLI and run
azd auth login - Pick a region where
gpt-4o-miniis available (e.g.eastus2) - See the Azure AI Foundry setup guide for details
- Install the Azure Developer CLI and run
-
Dev container not starting?
- Ensure Docker Desktop is running (for local development)
- Try rebuilding the container:
Ctrl+Shift+P→ "Dev Containers: Rebuild Container"
-
Application compilation errors?
- Ensure you're in the correct directory:
02-SetupDevEnvironment/examples/basic-chat-azure - Try cleaning and rebuilding:
mvn clean compile
- Ensure you're in the correct directory:
Need help?: Still having issues? Open an issue in the repository and we'll help you out.





