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

Java Spring Boot Deployment

Deployment is getting your application ready to run on a real server, like packing it up for a trip. You can bundle it into one file, set options for each place, and even put it in a container.

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
// Define the class Main
public class Main {
	// Program entry point: the JVM starts running here
	public static void main(String[] args) {
		String dockerfile = "FROM eclipse-temurin:17-jre\nCOPY app.jar app.jar\nENTRYPOINT [\"java\",\"-jar\",\"app.jar\"]";
		// Print a line to the console
		System.out.println(dockerfile);
	}
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Building a jar without the spring-boot-maven-plugin, so java -jar fails with 'no main manifest attribute' because it is not an executable fat jar.
  2. Leaving all Actuator endpoints exposed publicly, which can leak internal details; expose only what you need and secure it.
  3. Hard-coding database URLs and passwords in application.properties instead of using environment variables or profiles for each environment.
Chapter Summary
  • Spring Boot simplifies building Java applications and provides a quick way to set up a project.
  • You can build REST APIs, work with databases through Spring Data JPA, and add security.
  • Spring Boot also covers testing and deployment.
🔒

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.