### Development Setup with Docker Compose
Source: https://github.com/jdubois/dr-jskill/blob/main/references/DOCKER.md
Commands for setting up the development environment using Docker Compose. Includes options for basic setup and hot reloading with spring-boot-devtools by mounting the source code.
```bash
# Use docker-compose for easy setup
docker compose up
# Hot reload with spring-boot-devtools (mount source)
docker compose -f docker-compose-dev.yml up
```
--------------------------------
### Install Azure CLI and Extensions
Source: https://github.com/jdubois/dr-jskill/blob/main/references/AZURE.md
Installs the Azure CLI and the necessary Container Apps extension. Includes commands for macOS, Windows, and Linux, followed by Azure login and subscription setting.
```bash
# Install Azure CLI (if not already installed)
# macOS
brew install azure-cli
# Windows
# Download from: https://aka.ms/installazurecliwindows
# Linux
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
# Login to Azure
az login
# Set your subscription
az account set --subscription "YOUR_SUBSCRIPTION_ID"
# Install Container Apps extension
az extension add --name containerapp --upgrade
```
--------------------------------
### Setup PostgreSQL with Docker Compose (Bash)
Source: https://github.com/jdubois/dr-jskill/blob/main/scripts/README.md
This sequence of commands sets up a full-stack project to use PostgreSQL via Docker Compose. It involves copying a configuration file and then running the application, which automatically starts the database.
```bash
cp assets/compose.yaml my-fullstack-app/
cd my-fullstack-app
./mvnw spring-boot:run
```
--------------------------------
### Start Development Environment (Bash)
Source: https://github.com/jdubois/dr-jskill/blob/main/references/ANGULAR.md
This section provides commands to launch the development environment. It involves running the Spring Boot backend using Maven in one terminal and starting the Angular frontend development server with hot reload using `npm start` in another. The frontend is accessible at http://localhost:4200, with API calls proxied to the backend at http://localhost:8080.
```bash
# Terminal 1 - Spring Boot Backend:
./mvnw spring-boot:run
# Terminal 2 - Angular Frontend (with hot reload):
cd frontend
npm start
```
--------------------------------
### Start Vite Development Server (Bash)
Source: https://github.com/jdubois/dr-jskill/blob/main/references/VANILLA-JS.md
Command to start the Vite development server from the `frontend` directory. This command is part of the development testing setup, allowing for hot module replacement and rapid frontend development.
```bash
cd frontend && npm run dev
```
--------------------------------
### Create Angular Project with CLI
Source: https://github.com/jdubois/dr-jskill/blob/main/references/ANGULAR.md
Instructions to scaffold a new Angular project using the Angular CLI, including routing and CSS styling. It also covers installing Bootstrap for UI components.
```bash
# Install Angular CLI globally
npm install -g @angular/cli
# Create Angular project
ng new frontend --routing --style=css --skip-git
cd frontend
# Install Bootstrap
npm install bootstrap
```
--------------------------------
### GitHub Actions CI Workflow Setup (YAML)
Source: https://github.com/jdubois/dr-jskill/blob/main/references/PROJECT-SETUP.md
Provides a starter GitHub Actions workflow for CI. This workflow should be copied to `.github/workflows/ci.yml` to enable build, test, and Docker checks on every push.
```yaml
# Example content for .github/workflows/ci.yml
# This is a placeholder and the actual content would be in assets/ci/github-actions.yml
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Build with Maven
run: ./mvnw clean install
- name: Build and push Docker image
run: |
docker build -t my-app:${{ github.sha }}
# Add push logic if needed
```
--------------------------------
### Configure PostgreSQL Server Parameters
Source: https://github.com/jdubois/dr-jskill/blob/main/references/AZURE.md
Sets a specific parameter for an Azure PostgreSQL flexible server. This example configures the maximum number of connections. Requires resource group, server name, parameter name, and value.
```bash
az postgres flexible-server parameter set \
--resource-group $RESOURCE_GROUP \
--server-name $DB_SERVER_NAME \
--name max_connections \
--value 100
```
--------------------------------
### Start Development Environment (Bash)
Source: https://github.com/jdubois/dr-jskill/blob/main/references/VUE.md
This section outlines the commands to start the development environment for a full-stack application. It involves running the Spring Boot backend using Maven wrapper in one terminal and starting the Vue.js frontend development server with hot reload in another. The frontend is accessible at `http://localhost:5173`, with API calls proxied to the backend at `http://localhost:8080`.
```bash
# Terminal 1 - Spring Boot Backend:
./mvnw spring-boot:run
# Terminal 2 - Vue.js Frontend (with hot reload):
cd frontend
npm run dev
```
--------------------------------
### Stop and Start Azure PostgreSQL Database
Source: https://github.com/jdubois/dr-jskill/blob/main/references/AZURE.md
These commands allow you to stop and start an Azure PostgreSQL Flexible Server to manage costs. Stopping the server halts all compute and storage operations, saving money when the database is not actively used. Starting it resumes operations. This is ideal for development or non-production environments.
```bash
# Stop database to save costs
az postgres flexible-server stop \
--resource-group $RESOURCE_GROUP \
--name $DB_SERVER_NAME
# Start when needed
az postgres flexible-server start \
--resource-group $RESOURCE_GROUP \
--name $DB_SERVER_NAME
```
--------------------------------
### Vue.js Project Setup with Vite
Source: https://github.com/jdubois/dr-jskill/blob/main/references/VUE.md
Command-line instructions to create a new Vue.js project using Vite. It includes prompts for adding essential features like Vue Router, Pinia, Vitest, and ESLint, followed by dependency installation.
```bash
npm create vue@latest frontend
# Follow the prompts:
# ✔ Add TypeScript? … No
# ✔ Add JSX Support? … No
# ✔ Add Vue Router for Single Page Application development? … Yes
# ✔ Add Pinia for state management? … Yes
# ✔ Add Vitest for Unit Testing? … Yes
# ✔ Add an End-to-End Testing Solution? › No
# ✔ Add ESLint for code quality? … Yes
# ✔ Add Prettier for code formatting? … Yes
cd frontend
npm install
```
--------------------------------
### Start React Frontend Development Server (Bash)
Source: https://github.com/jdubois/dr-jskill/blob/main/references/REACT.md
This bash command navigates to the frontend directory and starts the React development server using npm. This enables hot reloading for rapid frontend development. The application will be accessible at http://localhost:5173.
```bash
cd frontend
npm run dev
```
--------------------------------
### Complete Azure Deployment Script with Database
Source: https://github.com/jdubois/dr-jskill/blob/main/references/AZURE.md
A comprehensive bash script to automate the deployment of an Azure Container App with a PostgreSQL database. It handles resource group creation, VNET and subnet setup, container registry provisioning, image building, PostgreSQL instance creation, and Container App deployment. Requires user to set configuration variables.
```bash
#!/bin/bash
set -e
# Configuration
RESOURCE_GROUP="myapp-rg"
LOCATION="eastus"
APP_NAME="myapp"
ACR_NAME="${APP_NAME}acr$RANDOM"
CONTAINER_APP_ENV="${APP_NAME}-env"
CONTAINER_APP_NAME="${APP_NAME}-app"
DB_SERVER_NAME="${APP_NAME}db$RANDOM"
DB_NAME="appdb"
DB_ADMIN_USER="pgadmin"
DB_ADMIN_PASSWORD="YourSecurePassword123!" # Change this!
VNET_NAME="${APP_NAME}-vnet"
SUBNET_APP="subnet-app"
SUBNET_DB="subnet-db"
echo "🚀 Deploying $APP_NAME with PostgreSQL to Azure..."
# Create resource group
echo "📦 Creating resource group..."
az group create \
--name $RESOURCE_GROUP \
--location $LOCATION \
--output none
# Create VNET
echo "🌐 Creating virtual network..."
az network vnet create \
--resource-group $RESOURCE_GROUP \
--name $VNET_NAME \
--location $LOCATION \
--address-prefix 10.0.0.0/16 \
--output none
# Create subnets
az network vnet subnet create \
--resource-group $RESOURCE_GROUP \
--vnet-name $VNET_NAME \
--name $SUBNET_APP \
--address-prefixes 10.0.0.0/23 \
--output none
az network vnet subnet create \
--resource-group $RESOURCE_GROUP \
--vnet-name $VNET_NAME \
--name $SUBNET_DB \
--address-prefixes 10.0.2.0/24 \
--delegations Microsoft.DBforPostgreSQL/flexibleServers \
--output none
# Create Container Registry
echo "🏗️ Creating Container Registry..."
az acr create \
--resource-group $RESOURCE_GROUP \
--name $ACR_NAME \
--sku Basic \
--admin-enabled true \
--output none
# Build and push image
echo "🐳 Building Docker image..."
az acr build \
--registry $ACR_NAME \
--image $APP_NAME:latest \
--file Dockerfile \
.
ACR_LOGIN_SERVER=$(az acr show --name $ACR_NAME --query loginServer -o tsv)
# Create PostgreSQL database
echo "🗄️ Creating PostgreSQL database (this may take 5-10 minutes)..."
az postgres flexible-server create \
--resource-group $RESOURCE_GROUP \
--name $DB_SERVER_NAME \
--location $LOCATION \
--admin-user $DB_ADMIN_USER \
--admin-password $DB_ADMIN_PASSWORD \
--sku-name Standard_B1ms \
--tier Burstable \
--storage-size 32 \
--version 16 \
--vnet $VNET_NAME \
--subnet $SUBNET_DB \
--yes \
--output none
az postgres flexible-server db create \
--resource-group $RESOURCE_GROUP \
--server-name $DB_SERVER_NAME \
--database-name $DB_NAME \
--output none
DB_HOST=$(az postgres flexible-server show \
--resource-group $RESOURCE_GROUP \
--name $DB_SERVER_NAME \
--query fullyQualifiedDomainName -o tsv)
# Get subnet ID
SUBNET_APP_ID=$(az network vnet subnet show \
--resource-group $RESOURCE_GROUP \
--vnet-name $VNET_NAME \
--name $SUBNET_APP \
--query id -o tsv)
# Create Container Apps Environment
echo "🌍 Creating Container Apps Environment..."
az containerapp env create \
--name $CONTAINER_APP_ENV \
--resource-group $RESOURCE_GROUP \
--location $LOCATION \
--infrastructure-subnet-resource-id $SUBNET_APP_ID \
--output none
```
--------------------------------
### Troubleshoot Container App Startup Issues with Azure CLI
Source: https://github.com/jdubois/dr-jskill/blob/main/references/AZURE.md
These commands help diagnose why a container app might not be starting correctly. They allow you to view recent logs, check the status of different revisions of the application, and restart the application if necessary. Ensure `CONTAINER_APP_NAME` and `RESOURCE_GROUP` are set.
```bash
# Check logs
az containerapp logs show \
--name $CONTAINER_APP_NAME \
--resource-group $RESOURCE_GROUP \
--tail 200
# Check revision status
az containerapp revision list \
--name $CONTAINER_APP_NAME \
--resource-group $RESOURCE_GROUP \
--output table
# Restart app
az containerapp revision restart \
--name $CONTAINER_APP_NAME \
--resource-group $RESOURCE_GROUP
```
--------------------------------
### Create Virtual Network for Container App and PostgreSQL
Source: https://github.com/jdubois/dr-jskill/blob/main/references/AZURE.md
Creates an Azure Virtual Network (VNet) and two subnets: one for the Container App and another for the PostgreSQL Flexible Server. This setup isolates network traffic and ensures proper connectivity between services. It requires the resource group, location, and VNet/subnet names.
```bash
# Create VNET
az network vnet create \
--resource-group $RESOURCE_GROUP \
--name $VNET_NAME \
--location $LOCATION \
--address-prefix 10.0.0.0/16
# Create subnet for Container Apps
az network vnet subnet create \
--resource-group $RESOURCE_GROUP \
--vnet-name $VNET_NAME \
--name $SUBNET_APP \
--address-prefixes 10.0.0.0/23
# Create subnet for PostgreSQL
az network vnet subnet create \
--resource-group $RESOURCE_GROUP \
--vnet-name $VNET_NAME \
--name $SUBNET_DB \
--address-prefixes 10.0.2.0/24 \
--delegations Microsoft.DBforPostgreSQL/flexibleServers
# Get subnet IDs
SUBNET_APP_ID=$(az network vnet subnet show \
--resource-group $RESOURCE_GROUP \
--vnet-name $VNET_NAME \
--name $SUBNET_APP \
--query id -o tsv)
```
--------------------------------
### Home Page Rendering in JavaScript
Source: https://github.com/jdubois/dr-jskill/blob/main/references/VANILLA-JS.md
Renders the home page content for the web application. It dynamically injects HTML into the 'content' element, including a welcome message, descriptive text, and a 'Getting Started' card with a test button. It also attaches an event listener to the test button to display an alert when clicked, confirming the JavaScript functionality.
```javascript
export function renderHomePage() {
const contentEl = document.getElementById('content')
contentEl.innerHTML = '
Welcome to Spring Boot
A modern web application built with Spring Boot and Vanilla JavaScript.
Getting Started
Your Spring Boot application with Vanilla JavaScript is running! This front-end
is connected to your REST API endpoints with hot reload during development.
'
// Add event listener
document.getElementById('testButton').addEventListener('click', () => {
alert('Button clicked! Your Vanilla JavaScript app is working.')
})
}
```
--------------------------------
### Local Native Image Compilation and Execution
Source: https://github.com/jdubois/dr-jskill/blob/main/references/GRAALVM.md
These bash commands guide the local build and execution of a native Spring Boot application. It includes steps for compiling the native image using Maven, running the generated executable, and testing with Docker.
```bash
# Build native image locally (requires GraalVM installed)
./mvnw native:compile -Pnative -DskipTests
# Run the native executable (name matches your artifactId)
./target/myapp
# Test with Docker
docker build -f Dockerfile-native -t myapp-native:test .
docker run -p 8080:8080 myapp-native:test
# Verify startup time
curl http://localhost:8080/actuator/health
```
--------------------------------
### Migrating @MockBean to @MockitoBean (Java)
Source: https://github.com/jdubois/dr-jskill/blob/main/references/SPRING-BOOT-4.md
This example demonstrates the migration from the deprecated `@MockBean` annotation to the recommended `@MockitoBean` in Spring Boot 4 tests. `@MockitoBean` should be used from the start for new projects.
```java
// Before Spring Boot 4:
// @MockBean
// private MyService myService;
// After Spring Boot 4:
@MockitoBean
private MyService myService;
```
--------------------------------
### Docker Image Build (Bash)
Source: https://github.com/jdubois/dr-jskill/blob/main/scripts/README.md
These commands demonstrate how to build Docker images for a project. One command builds a standard JVM image, while the other builds a GraalVM native image using a specific Dockerfile.
```bash
# Standard JVM image
docker build -t my-project .
# GraalVM native image
docker build -f Dockerfile-native -t my-project-native .
```
--------------------------------
### Standard Maven Build and Run (Bash)
Source: https://github.com/jdubois/dr-jskill/blob/main/scripts/README.md
This is the standard command to build and run a project using Maven. It navigates to the project directory and then executes the Spring Boot run goal.
```bash
cd my-project
./mvnw spring-boot:run
```
--------------------------------
### TestContainers 2.0 PostgreSQLContainer Usage
Source: https://github.com/jdubois/dr-jskill/blob/main/references/SPRING-BOOT-4.md
Shows the updated usage of PostgreSQLContainer in TestContainers 2.0, highlighting the removal of generics and the direct instantiation approach. This change simplifies container setup.
```java
// Package rename: org.testcontainers.containers.PostgreSQLContainer -> org.testcontainers.postgresql.PostgreSQLContainer
// Artifact rename: org.testcontainers:postgresql -> org.testcontainers:testcontainers-postgresql
// OLD (TestContainers < 2.0):
// import org.testcontainers.containers.PostgreSQLContainer;
// new PostgreSQLContainer<>("postgres:15")
// NEW (TestContainers 2.0+):
import org.testcontainers.postgresql.PostgreSQLContainer;
// PostgreSQLContainer is no longer generic
new PostgreSQLContainer("postgres:15")
```
--------------------------------
### Production Image Build and Deployment
Source: https://github.com/jdubois/dr-jskill/blob/main/references/DOCKER.md
Steps to build, tag, push, and deploy a production-ready Docker image. This process ensures the application is packaged correctly and made available in a container registry for deployment.
```bash
# Build production image
docker build -t myapp:1.0.0 .
# Tag and push to registry
docker tag myapp:1.0.0 myregistry.com/myapp:1.0.0
docker push myregistry.com/myapp:1.0.0
# Deploy with specific version
docker run -d -p 8080:8080 myregistry.com/myapp:1.0.0
```
--------------------------------
### Update Frontend package.json Scripts (JSON)
Source: https://github.com/jdubois/dr-jskill/blob/main/references/ANGULAR.md
This JSON snippet defines the scripts for the Angular frontend project in `package.json`. It includes commands for starting the development server (`npm start`), building the production version (`npm run build`), watching for changes during development (`npm run watch`), and running tests (`npm test`). These scripts are invoked by the frontend-maven-plugin and directly by developers.
```json
{
"name": "frontend",
"version": "1.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build --configuration production",
"watch": "ng build --watch --configuration development",
"test": "ng test"
}
}
```
--------------------------------
### View Container Logs
Source: https://github.com/jdubois/dr-jskill/blob/main/references/DOCKER.md
Commands to view logs from Docker containers. Allows viewing specific application logs or all service logs within a Docker Compose setup, with an option to follow the logs in real-time.
```bash
# View application logs
docker logs spring-boot-app -f
# View all service logs
docker compose logs -f
```
--------------------------------
### Production Build and Run (Bash)
Source: https://github.com/jdubois/dr-jskill/blob/main/references/ANGULAR.md
This command sequence details how to create a production-ready build. It first cleans the project and packages both the frontend and backend into a single executable JAR file using `./mvnw clean package`. The application can then be run using `java -jar target/my-app.jar` and accessed at http://localhost:8080.
```bash
# Build everything (frontend + backend)
./mvnw clean package
# Run the packaged application
java -jar target/my-app.jar
```
--------------------------------
### Create In-Memory Users for Development
Source: https://github.com/jdubois/dr-jskill/blob/main/references/SECURITY.md
Provides a UserDetailsService implementation that stores user credentials directly in memory. This is suitable for development and testing purposes, allowing quick setup of users with specified usernames, passwords, and roles.
```java
@Bean
public UserDetailsService userDetailsService() {
UserDetails user = User.builder()
.username("user")
.password(passwordEncoder().encode("password"))
.roles("USER")
.build();
UserDetails admin = User.builder()
.username("admin")
.password(passwordEncoder().encode("admin"))
.roles("USER", "ADMIN")
.build();
return new InMemoryUserDetailsManager(user, admin);
}
```
--------------------------------
### Database Connection Troubleshooting
Source: https://github.com/jdubois/dr-jskill/blob/main/references/DOCKER.md
Utilities for troubleshooting database connection issues within Docker. Includes commands to check PostgreSQL readiness and connect to the database using psql.
```bash
# Check if PostgreSQL is ready
docker exec postgres-db pg_isready -U user
# Connect to database
docker exec -it postgres-db psql -U user -d mydb
```
--------------------------------
### Build and Push Docker Image to ACR
Source: https://github.com/jdubois/dr-jskill/blob/main/references/AZURE.md
Builds a Docker image from the current directory (assumed to be a Spring Boot project) and pushes it to the Azure Container Registry. Requires Docker to be installed and logged into ACR.
```bash
# Get ACR login server
ACR_LOGIN_SERVER=$(az acr show \
--name $ACR_NAME \
--query loginServer \
--output tsv)
# Login to ACR
az acr login --name $ACR_NAME
# Build and push image (from your Spring Boot project directory)
docker build -t $ACR_LOGIN_SERVER/$APP_NAME:latest .
docker push $ACR_LOGIN_SERVER/$APP_NAME:latest
```
--------------------------------
### Implement SecurityUser for UserDetails
Source: https://github.com/jdubois/dr-jskill/blob/main/references/SECURITY.md
A custom implementation of Spring Security's UserDetails interface. It wraps the application's User entity, providing the necessary methods for authentication, such as getting authorities, password, username, and account status.
```java
public class SecurityUser implements UserDetails {
private final User user;
public SecurityUser(User user) {
this.user = user;
}
@Override
public Collection extends GrantedAuthority> getAuthorities() {
return user.getRoles().stream()
.map(role -> new SimpleGrantedAuthority("ROLE_" + role))
.collect(Collectors.toList());
}
@Override
public String getPassword() {
return user.getPassword();
}
@Override
public String getUsername() {
return user.getUsername();
}
@Override
public boolean isAccountNonExpired() {
return true;
}
@Override
public boolean isAccountNonLocked() {
return true;
}
@Override
public boolean isCredentialsNonExpired() {
return true;
}
@Override
public boolean isEnabled() {
return user.isEnabled();
}
}
```
--------------------------------
### Create React Project with Vite
Source: https://github.com/jdubois/dr-jskill/blob/main/references/REACT.md
Command to initialize a new React project using Vite, followed by dependency installation. This sets up the basic structure for the front-end application.
```bash
# Create React project with Vite
npm create vite@latest frontend -- --template react
cd frontend
npm install
# Install React Router and other dependencies
npm install react-router-dom
```
--------------------------------
### Testcontainers 2.x Artifact and Package Renames (XML & Java)
Source: https://github.com/jdubois/dr-jskill/blob/main/references/SPRING-BOOT-4.md
Shows the updated Maven artifact ID and Java package name for Testcontainers 2.x. The artifact is now `testcontainers-postgresql` (example), and the package for containers like `PostgreSQLContainer` has changed.
```xml
postgresqltestcontainers-postgresql
```
```java
// WRONG (TC 1.x):
import org.testcontainers.containers.PostgreSQLContainer;
// CORRECT (TC 2.x):
import org.testcontainers.postgresql.PostgreSQLContainer;
```
--------------------------------
### Create Basic Spring Boot Project (Node.js)
Source: https://github.com/jdubois/dr-jskill/blob/main/SKILL.md
Creates a minimal Spring Boot project with essential dependencies using a Node.js script. This is suitable for starting new projects that require only the core Spring Boot setup.
```bash
node scripts/create-basic-project.mjs
```
--------------------------------
### Build and Run Spring Boot Docker Image (JVM)
Source: https://github.com/jdubois/dr-jskill/blob/main/references/DOCKER.md
These bash commands demonstrate how to build a Docker image for a Spring Boot application using a provided Dockerfile and then run the container. The `docker build` command tags the image, and `docker run` maps the application port to the host. This is for standard JVM-based deployments.
```bash
# Build the image
docker build -t my-spring-app .
# Run the container
docker run -p 8080:8080 my-spring-app
```
--------------------------------
### HTML Entry Point for Vanilla JavaScript Application
Source: https://github.com/jdubois/dr-jskill/blob/main/references/VANILLA-JS.md
This HTML file serves as the main entry point for the frontend application. It sets up the basic document structure, includes meta tags, a title, and placeholders for navigation, main content, and footer. It also links the main JavaScript module.
```html
Spring Boot App
```
--------------------------------
### Get PostgreSQL Database Hostname
Source: https://github.com/jdubois/dr-jskill/blob/main/references/AZURE.md
Retrieves the fully qualified domain name (FQDN) of an Azure PostgreSQL flexible server. This is often used to construct connection strings. Requires resource group and server name.
```bash
DB_HOST=$(az postgres flexible-server show \
--resource-group $RESOURCE_GROUP \
--name $DB_SERVER_NAME \
--query fullyQualifiedDomainName -o tsv)
```
--------------------------------
### Create Project Script Execution (Node.js)
Source: https://github.com/jdubois/dr-jskill/blob/main/scripts/README.md
Scripts for creating projects are designed to run natively on macOS, Linux, and Windows using Node.js. They rely on version management from `versions.json` and do not require additional shell scripting tools.
```bash
node scripts/create-project-latest.mjs
```
--------------------------------
### Migrating @MockBean to @MockitoBean in Spring Boot 4
Source: https://github.com/jdubois/dr-jskill/blob/main/references/SPRING-BOOT-4.md
Demonstrates the migration from the deprecated @MockBean annotation to the new @MockitoBean for mocking beans in Spring Boot 4 tests. Includes an example of creating a custom annotation for shared mocks.
```java
// OLD (Deprecated):
import org.springframework.boot.test.mock.mockito.MockBean;
@SpringBootTest
class MyTest {
@MockBean
private UserService userService;
}
// NEW (Spring Boot 4):
import org.springframework.test.context.bean.override.mockito.MockitoBean;
@SpringBootTest
class MyTest {
@MockitoBean
private UserService userService;
}
// For shared mocks across tests:
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@MockitoBean(types = {UserService.class, OrderService.class})
public @interface SharedMocks {
}
@SpringBootTest
@SharedMocks
class ApplicationTests {
// Clean and reusable
}
```
--------------------------------
### Get Azure Container App URL
Source: https://github.com/jdubois/dr-jskill/blob/main/references/AZURE.md
Retrieves the fully qualified domain name (FQDN) of an Azure Container App. This is useful for accessing the deployed application. It requires the container app name and resource group name as input.
```bash
az containerapp show \
--name $CONTAINER_APP_NAME \
--resource-group $RESOURCE_GROUP \
--query properties.configuration.ingress.fqdn \
--output tsv
```
--------------------------------
### Activating Spring Profiles
Source: https://github.com/jdubois/dr-jskill/blob/main/references/CONFIGURATION.md
Shows various methods for activating Spring Boot profiles, including command-line arguments, environment variables, Docker environment variables, and directly within `application.properties` (though the latter is not recommended for production).
```bash
# Via Command Line:
# Single profile
java -jar app.jar --spring.profiles.active=prod
# Multiple profiles (comma-separated)
java -jar app.jar --spring.profiles.active=prod,monitoring
```
```bash
# Via Environment Variable:
export SPRING_PROFILES_ACTIVE=prod
java -jar app.jar
```
```bash
# Via Docker:
docker run -e SPRING_PROFILES_ACTIVE=prod -p 8080:8080 myapp:latest
```
```properties
# Via application.properties (not recommended for production):
spring.profiles.active=dev
```
--------------------------------
### Spring Boot Application Properties Example
Source: https://github.com/jdubois/dr-jskill/blob/main/references/CONFIGURATION.md
Demonstrates common server, application, logging, database, JPA, and actuator configurations using the `.properties` file format. This format is recommended for its tooling support and readability.
```properties
# Server Configuration
server.port=8080
server.compression.enabled=true
server.compression.mime-types=text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json
# Application Information
spring.application.name=my-spring-boot-app
spring.application.version=@project.version@
# Logging Configuration
logging.level.root=INFO
logging.level.com.example.myapp=DEBUG
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} - %logger{36} - %msg%n
# Database Configuration
spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
spring.datasource.username=user
spring.datasource.password=password
spring.datasource.hikari.maximum-pool-size=10
spring.datasource.hikari.minimum-idle=5
# JPA Configuration
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.show-sql=false
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.open-in-view=false
# Actuator Configuration
management.endpoints.web.exposure.include=health,info,metrics,prometheus
management.endpoint.health.show-details=when-authorized
management.metrics.export.prometheus.enabled=true
```
--------------------------------
### Deploy Spring Boot App to Azure Container Apps
Source: https://github.com/jdubois/dr-jskill/blob/main/references/AZURE.md
Deploys the Docker image to Azure Container Apps. Configures ingress, CPU/memory limits, replica counts, and environment variables. Includes an example of setting up autoscaling rules.
```bash
# Get ACR credentials
ACR_USERNAME=$(az acr credential show \
--name $ACR_NAME \
--query username \
--output tsv)
ACR_PASSWORD=$(az acr credential show \
--name $ACR_NAME \
--query passwords[0].value \
--output tsv)
# Create Container App
az containerapp create \
--name $CONTAINER_APP_NAME \
--resource-group $RESOURCE_GROUP \
--environment $CONTAINER_APP_ENV \
--image $ACR_LOGIN_SERVER/$APP_NAME:latest \
--registry-server $ACR_LOGIN_SERVER \
--registry-username $ACR_USERNAME \
--registry-password $ACR_PASSWORD \
--target-port 8080 \
--ingress external \
--cpu 0.5 \
--memory 1Gi \
--min-replicas 0 \
--max-replicas 10 \
--env-vars \
"SERVER_PORT=8080" \
"JAVA_OPTS=-XX:+UseContainerSupport -XX:MaxRAMPercentage=75.0"
# Optional: Autoscaling rule (HTTP RPS)
az containerapp up \
--name $CONTAINER_APP_NAME \
--resource-group $RESOURCE_GROUP \
--source . \
--target-port 8080 \
--ingress external \
--max-replicas 10 \
--min-replicas 0 \
--scale-rules "http={concurrency=50}" \
--env-vars "JAVA_OPTS=-XX:+UseContainerSupport -XX:MaxRAMPercentage=75.0"
# Managed Identity + Key Vault secrets (example)
az identity create -g $RESOURCE_GROUP -n ${APP_NAME}-mi
IDENTITY_ID=$(az identity show -g $RESOURCE_GROUP -n ${APP_NAME}-mi --query id -o tsv)
az containerapp identity assign \
--name $CONTAINER_APP_NAME \
--resource-group $RESOURCE_GROUP \
--identities $IDENTITY_ID
# In Key Vault (once): grant access to managed identity
# az keyvault set-policy --name $KEY_VAULT --object-id $IDENTITY_ID --secret-permissions get list
# In Container App: set env var to a Key Vault secret reference
# --set-secrets DB_PASSWORD=keyvaultref://${KEY_VAULT}/secrets/DB_PASSWORD
```
--------------------------------
### Spring Boot Application Configuration via Environment Variables
Source: https://github.com/jdubois/dr-jskill/blob/main/references/DOCKER.md
Defines environment variables for configuring a Spring Boot application within a Docker Compose setup. This includes database connection details (URL, username, password), JPA/Hibernate settings, and the server port.
```yaml
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/mydb
SPRING_DATASOURCE_USERNAME: user
SPRING_DATASOURCE_PASSWORD: password
SPRING_JPA_HIBERNATE_DDL_AUTO: update
SERVER_PORT: 8080
```
--------------------------------
### Docker Compose for Native Spring Boot with PostgreSQL
Source: https://github.com/jdubois/dr-jskill/blob/main/references/DOCKER.md
Orchestrates a development environment with a GraalVM 25 native Spring Boot application and PostgreSQL 16. This setup leverages the benefits of native compilation for faster startup and reduced resource consumption, ideal for microservices and serverless deployments.
```bash
# Start all services with native image
docker compose -f docker-compose-native.yml up -d
# View logs
docker compose -f docker-compose-native.yml logs -f
# Stop all services
docker compose -f docker-compose-native.yml down
```
--------------------------------
### Create Vite Vanilla JS Project with npm
Source: https://github.com/jdubois/dr-jskill/blob/main/references/VANILLA-JS.md
This command initializes a new front-end project using Vite with the vanilla JavaScript template. It assumes you are in the root directory of your Spring Boot project. After creation, it navigates into the new project directory and installs the necessary Node.js dependencies.
```bash
# Create Vite project with vanilla template
npm create vite@latest frontend -- --template vanilla
cd frontend
npm install
```
--------------------------------
### Get Azure Container App Status
Source: https://github.com/jdubois/dr-jskill/blob/main/references/AZURE.md
This command retrieves the current running status of an Azure Container App. The output is typically a string indicating whether the app is running, stopped, or in another state. This helps in quickly assessing the application's operational status.
```bash
# Get app status
az containerapp show \
--name $CONTAINER_APP_NAME \
--resource-group $RESOURCE_GROUP \
--query "properties.runningStatus" \
--output tsv
```
--------------------------------
### Run Application with Docker Compose (Bash)
Source: https://github.com/jdubois/dr-jskill/blob/main/scripts/README.md
After copying the necessary Docker files, this command initiates the application's containers using Docker Compose. It allows for running the application within a Dockerized environment.
```bash
cd my-project
docker compose up -d
```
--------------------------------
### Test Azure Container App Health Endpoint
Source: https://github.com/jdubois/dr-jskill/blob/main/references/AZURE.md
Tests the health endpoint of a deployed Azure Container App using curl. It first retrieves the application URL and then sends a GET request to the /actuator/health endpoint. The expected output is a JSON object indicating the application's status.
```bash
# Get the URL
APP_URL="https://$(az containerapp show \
--name $CONTAINER_APP_NAME \
--resource-group $RESOURCE_GROUP \
--query properties.configuration.ingress.fqdn \
--output tsv)"
# Test health endpoint
curl $APP_URL/actuator/health
# Expected: {"status":"UP"}
```
--------------------------------
### Environment Variable Configuration (.env.sample)
Source: https://github.com/jdubois/dr-jskill/blob/main/references/PROJECT-SETUP.md
This .env.sample file provides placeholder values and comments for essential environment variables. It documents required variables for Spring profiles, database connections, and application secrets. This file should be committed, while the actual .env file (containing sensitive data) should be ignored.
```dotenv
# Spring profiles
SPRING_PROFILES_ACTIVE=dev
# Database (PostgreSQL)
DATABASE_URL=jdbc:postgresql://localhost:5432/mydb
DATABASE_USERNAME=user
DATABASE_PASSWORD=change-me
# Testcontainers overrides (optional)
TESTCONTAINERS_RYUK_DISABLED=false
# Application secrets (NEVER commit real values)
APP_API_KEY=replace-me
APP_API_SECRET=replace-me
```
--------------------------------
### Common Docker and Docker Compose Commands
Source: https://github.com/jdubois/dr-jskill/blob/main/references/DOCKER.md
A collection of frequently used Docker and Docker Compose commands for building images, running containers, managing services, viewing logs, and cleaning up unused resources.
```bash
# Build image
docker build -t my-app .
# Run container
docker run -p 8080:8080 my-app
# Start services
docker compose up -d
# Stop services
docker compose down
# View logs
docker compose logs -f spring-app
# Rebuild and restart
docker compose up -d --build
# Access container shell
docker exec -it spring-boot-app bash
# Clean up unused images
docker system prune -a
```
--------------------------------
### Define Docker Compose for Spring Boot Development
Source: https://github.com/jdubois/dr-jskill/blob/main/references/DOCKER.md
This YAML file defines a PostgreSQL service for use with Spring Boot's `spring-boot-docker-compose` dependency. It specifies the image, environment variables, port mapping, health check, resource limits, and volume for data persistence. This setup automates PostgreSQL container management during development.
```yaml
services:
postgres:
image: postgres:16-alpine
environment:
POSTGRES_DB: mydb
POSTGRES_USER: user
POSTGRES_PASSWORD: password
ports:
- "5432:5432"
healthcheck:
test: ["CMD", "pg_isready", "-U", "user"]
interval: 10s
timeout: 5s
retries: 5
deploy:
resources:
limits:
memory: 512m
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data:
```