Java Spring Boot की Deployment
In this page:
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
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");
}
}
Login to try C/C++/Java/PHP code in the editor
Dynamic Profiles
Profiles आपको environments के बीच configuration अलग रखने देते हैं -- local development के लिए lightweight, permissive settings बनाम staging या production के लिए सख्त, high-security settings -- और Spring Boot कौन सा profile active है इसके आधार पर सही property set अपने आप activate करता है।
उदाहरण: Dynamic Profiles
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);
}
}
Login to try C/C++/Java/PHP code in the editor
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
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);
}
}
Login to try C/C++/Java/PHP code in the editor
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
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");
}
}
Login to try C/C++/Java/PHP code in the editor
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
// 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);
}
}
Login to try C/C++/Java/PHP code in the editor
spring-boot-maven-pluginके बिना jar बनाना, जिससेjava -jar'no main manifest attribute' के साथ fail हो जाता है क्योंकि यह एक executable fat jar नहीं है।- सभी Actuator endpoints को publicly उजागर छोड़ देना, जो internal details leak कर सकता है; सिर्फ जो चाहिए उसे उजागर करें और उसे secure करें।
- हर 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: