← Back to Advanced Java Course | Chapter 10: Spring Boot | Lesson 6 of 6

Java Spring Boot Deployment

Fat Jar Executables

Spring Boot builds fat executable jars that bundle your application's compiled bytecode together with an embedded servlet web server (Tomcat by default). This means a single jar file is enough to run the app anywhere a JVM is installed, with no separate application-server setup required.

Example: Fat Jar Executables

java
public class Main {
	public static void main(String[] args) {
		// mvn package produces target/app.jar bundling Tomcat inside -- run with: java -jar app.jar
		System.out.println("A single jar bundles the app and an embedded server");
	}
}

Dynamic Profiles

Profiles let you separate configuration between environments -- lightweight, permissive settings for local development versus stricter, high-security settings for staging or production -- and Spring Boot activates the right property set automatically based on which profile is active.

Example: Dynamic Profiles

java
public class Main {
	public static void main(String[] args) {
		String activeProfile = System.getProperty("spring.profiles.active", "dev"); // dev vs prod settings
		System.out.println("Active profile: " + activeProfile);
	}
}

Dynamic Environment Configuration

Injecting configuration through environment variables lets you change database URLs, API keys, or feature flags at deploy time without rebuilding the application, which is essential for keeping secrets and per-environment settings out of your source code.

Example: Dynamic Environment Configuration

java
public class Main {
	public static void main(String[] args) {
		String dbUrl = System.getenv().getOrDefault("DATABASE_URL", "jdbc:default"); // changed at deploy time, no rebuild
		System.out.println(dbUrl);
	}
}

Actuator Monitoring

Spring Boot Actuator exposes built-in monitoring endpoints that report on application health, active thread counts, and other performance indicators, giving operators visibility into a running service without needing custom instrumentation code.

Example: Actuator Monitoring

java
public class Main {
	public static void main(String[] args) {
		// GET /actuator/health, /actuator/metrics -- built-in monitoring endpoints
		System.out.println("Actuator exposes health and metrics without custom instrumentation");
	}
}

Docker Containerization

Packaging a fat executable jar into a Docker image is the standard way to prepare a Spring Boot app for cloud-native, containerized deployment pipelines, since the resulting image needs nothing installed on the host besides a container runtime.

Example: Docker Containerization

java
public class Main {
	public static void main(String[] args) {
		String dockerfile = "FROM eclipse-temurin:17-jre\nCOPY app.jar app.jar\nENTRYPOINT [\"java\",\"-jar\",\"app.jar\"]";
		System.out.println(dockerfile);
	}
}
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.