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

Java Spring Boot की Deployment

Deployment आपके application को किसी असली server पर चलने के लिए तैयार करना है, जैसे किसी trip के लिए उसे पैक करना। आप इसे एक file में bundle कर सकते हैं, हर जगह के लिए options सेट कर सकते हैं, और इसे एक container में भी डाल सकते हैं।

Fat Jar Executables

Spring Boot fat executable jars बनाता है जो आपके application के compiled bytecode को एक embedded servlet web server (default रूप से Tomcat) के साथ bundle कर देते हैं। इसका मतलब है कि एक single jar file किसी भी जगह चलाने के लिए काफी है जहां JVM installed हो, बिना किसी अलग application-server setup की ज़रूरत के।

उदाहरण: 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 आपको environments के बीच configuration अलग रखने देते हैं -- local development के लिए lightweight, permissive settings बनाम staging या production के लिए सख्त, high-security settings -- और Spring Boot कौन सा profile active है इसके आधार पर सही property set अपने आप activate करता है।

उदाहरण: 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

environment variables के ज़रिए configuration inject करना आपको deploy time पर database URLs, API keys, या feature flags को बिना application rebuild किए बदलने देता है, जो secrets और per-environment settings को आपके source code से बाहर रखने के लिए ज़रूरी है।

उदाहरण: 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 built-in monitoring endpoints उजागर करता है जो application health, active thread counts, और दूसरे performance indicators की report देते हैं, operators को किसी चल रही service में बिना custom instrumentation code के visibility देते हुए।

उदाहरण: 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

एक fat executable jar को Docker image में package करना किसी Spring Boot app को cloud-native, containerized deployment pipelines के लिए तैयार करने का standard तरीका है, क्योंकि resulting image को host पर container runtime के अलावा कुछ भी install किए जाने की ज़रूरत नहीं।

उदाहरण: 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. #}
आम गलतियां
  1. spring-boot-maven-plugin के बिना jar बनाना, जिससे java -jar 'no main manifest attribute' के साथ fail हो जाता है क्योंकि यह एक executable fat jar नहीं है।
  2. सभी Actuator endpoints को publicly उजागर छोड़ देना, जो internal details leak कर सकता है; सिर्फ जो चाहिए उसे उजागर करें और उसे secure करें।
  3. हर environment के लिए environment variables या profiles का उपयोग करने के बजाय application.properties में database URLs और passwords को hard-code करना।
चैप्टर सारांश
  • Spring Boot Java applications बनाना सरल बनाता है और project setup का एक तेज़ तरीका प्रदान करता है।
  • आप REST APIs बना सकते हैं, Spring Data JPA से databases के साथ काम कर सकते हैं, और security जोड़ सकते हैं।
  • Spring Boot testing और 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.