Skip to main content
Innovation|Innovation

Spring Boot Essentials: Java Applications कैसे जीवंत होती हैं

Spring Boot की मूल बातों के लिए एक beginner-friendly guide — application lifecycle, IoC container, dependency injection, annotations cheat sheet, N-Tier architecture, records के साथ DTOs, global exception handling, और @Valid के साथ validation।

11 अप्रैल 202614 min read

Spring Boot क्या है और आपको क्यों परवाह करनी चाहिए?

कल्पना कीजिए कि आप एक घर बनाना चाहते हैं। आप हर ईंट, तार, और पाइप अलग से खरीद सकते हैं, पता लगा सकते हैं कि वे कैसे जुड़ते हैं, और केवल plumbing पर महीनों बिता सकते हैं। या आप एक builder को hire कर सकते हैं जो पहले से ही blueprint जानता है, जिसके पास सामग्री तैयार है, और आपको एक तैयार घर सौंपता है — आप बस paint का color चुनते हैं।

यही वह है जो Spring Boot Java developers के लिए करता है। सादा Java आपको ईंटें देता है। Spring Framework आपको एक blueprint देता है। Spring Boot आपको एक तैयार घर देता है जिसमें lights पहले से ही चालू हैं।

इस guide में, आप सीखेंगे कि एक Spring Boot application कैसे शुरू होती है, यह आपकी objects का management कैसे करती है, आप अपने code को साफ layers में कैसे organize करते हैं, और आप errors और validation को कैसे संभालते हैं — सभी व्यावहारिक code उदाहरणों के साथ जिन्हें आप आज चला सकते हैं।

Application Lifecycle: main() से Ready तक

हर Spring Boot application एक single class के साथ शुरू होती है। इसे एक computer पर power button दबाने जैसा सोचें — एक click, और दर्जनों चीजें पर्दे के पीछे होती हैं।

@SpringBootApplication — सभी पर शासन करने वाला एक Annotation

@SpringBootApplication वास्तव में तीन annotations को एक में मिलाकर बनाया गया है:

  • @SpringBootConfiguration — इस class को एक configuration source के रूप में marks करता है (एक settings file की तरह)
  • @EnableAutoConfiguration — Spring Boot को बताता है कि आपके पास कौन सी libraries हैं उसके आधार पर चीजों को स्वचालित रूप से configure करे
  • @ComponentScan — Spring को इस package और नीचे में विशेष annotations वाले classes की खोज करने के लिए कहता है
@SpringBootApplication
public class BookStoreApplication {
    public static void main(String[] args) {
        SpringApplication.run(BookStoreApplication.class, args);
    }
}

जब आप इसे चलाते हैं, Spring Boot निम्नलिखित क्रम में करता है:

  1. ApplicationContext बनाता है — एक container जो आपकी सभी objects रखता है (जिन्हें "beans" कहा जाता है)
  2. Components के लिए scan करता है@Service, @Repository, @Controller, आदि वाली हर class को ढूंढता है
  3. Auto-configures — देखता है कि आपके पास एक database driver है? यह एक connection pool set up करता है। एक web dependency है? यह एक embedded Tomcat server शुरू करता है।
  4. Startup hooks चलाता है — किसी भी CommandLineRunner या ApplicationRunner beans को execute करता है
  5. Ready — आपकी app जीवित है और requests के लिए सुन रही है
// Want to run something on startup? Use CommandLineRunner
@Component
public class DataLoader implements CommandLineRunner {
    @Override
    public void run(String... args) {
        System.out.println("Application started! Loading initial data...");
    }
}

IoC Container: Spring को आपके लिए पकाने दें

IoC का अर्थ है Inversion of Control। यहाँ सबसे सरल उपमा है:

IoC के बिना (घर पर खाना बनाना): आप store जाते हैं, सामग्री खरीदते हैं, सब्जियाँ काटते हैं, stove गरम करते हैं, खाना बनाते हैं, बर्तन धोते हैं। आप सब कुछ नियंत्रित करते हैं।

IoC के साथ (restaurant में खाना): आप बैठते हैं, menu से order करते हैं, और chef आपके लिए खाना लाता है। आप control नहीं करते कि खाना कैसे बनाया जाता है — restaurant करता है। आप बस यह कहते हैं कि आप क्या चाहते हैं।

Spring Boot में, IoC Container (जिसे ApplicationContext भी कहा जाता है) restaurant है। आपकी classes dishes हैं। आप वर्णन करते हैं कि आपको क्या चाहिए, और Spring आपके लिए सब कुछ बनाता है, जोड़ता है, और manage करता है।

Bean क्या है?

एक bean बस एक Java object है जिसे Spring बनाता है और manage करता है। new ProductService() लिखने के बजाय, Spring इसे बनाता है, memory में रखता है, और जिसे भी इसकी आवश्यकता होती है उसे देता है।

// YOU do not write this:
ProductRepository repo = new ProductRepository();
ProductService service = new ProductService(repo);

// SPRING does it for you — you just ask:
@Service
public class ProductService {
    private final ProductRepository repository;

    // Spring sees this constructor, finds a ProductRepository bean,
    // and passes it in automatically
    public ProductService(ProductRepository repository) {
        this.repository = repository;
    }
}

Dependency Injection: जो आपको चाहिए उसे माँगना

Dependency Injection (DI) IoC का कैसे है। यह है कि Spring आपकी class को वे objects कैसे देता है जिन पर यह निर्भर है। इसे room service order करने की तरह सोचें — आप front desk को call करते हैं और कहते हैं "मुझे towels चाहिए," और वे आपके दरवाजे पर towels लाते हैं। आप laundry room में खुद नहीं जाते।

तीन प्रकार के Injection

// 1. CONSTRUCTOR INJECTION (recommended — the best way)
@Service
public class OrderService {
    private final ProductRepository productRepo;
    private final EmailService emailService;

    // Spring injects both dependencies through the constructor
    public OrderService(ProductRepository productRepo, EmailService emailService) {
        this.productRepo = productRepo;
        this.emailService = emailService;
    }
}

// 2. SETTER INJECTION (for optional dependencies)
@Service
public class ReportService {
    private CacheService cacheService;

    @Autowired(required = false)
    public void setCacheService(CacheService cacheService) {
        this.cacheService = cacheService;
    }
}

// 3. FIELD INJECTION (avoid — hard to test)
@Service
public class NotificationService {
    @Autowired  // Works but NOT recommended
    private EmailService emailService;
}

Constructor injection क्यों सबसे अच्छा है:

  • आपके fields final हो सकते हैं — एक बार set होने के बाद, वे कभी नहीं बदलते
  • Test करना आसान — बस constructor में mock objects pass करें
  • यदि कोई dependency गायब है, तो app startup पर विफल हो जाती है (runtime पर नहीं जब कोई user कुछ click करता है)

Annotations Cheat Sheet: वे Labels जो Spring को बताते हैं क्या करना है

Annotations एक party में name tags की तरह हैं। जब आप एक class पर @Service लगाते हैं, तो आप Spring को बता रहे हैं: "अरे, मैं एक service हूँ — कृपया मुझे manage करें।" यहाँ हर वह annotation है जो आपको जाननी चाहिए:

Component Annotations (Spring इनके लिए scan करता है)

// @Component — generic "I am a Spring-managed bean"
@Component
public class PdfGenerator { }

// @Service — business logic layer (same as @Component, but clearer intent)
@Service
public class EmployeeService {
    public Employee findById(Long id) { ... }
}

// @Repository — data access layer (adds automatic exception translation)
@Repository
public class EmployeeRepository {
    public Employee save(Employee employee) { ... }
}

// @RestController — handles HTTP requests and returns JSON directly
@RestController
@RequestMapping("/api/products")
public class ProductController {
    @GetMapping("/{id}")
    public Product getProduct(@PathVariable Long id) { ... }
}

// @Controller — handles HTTP requests and returns HTML views
@Controller
public class HomeController {
    @GetMapping("/")
    public String home(Model model) {
        return "index";  // returns the index.html template
    }
}

Configuration Annotations

// @Bean — manually create a bean inside a @Configuration class
@Configuration
public class AppConfig {

    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    @Bean
    public ObjectMapper objectMapper() {
        return new ObjectMapper()
            .registerModule(new JavaTimeModule())
            .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    }
}

// @Value — inject values from application.properties
@Service
public class EmailService {
    @Value("${app.email.from:noreply@example.com}")
    private String fromAddress;

    @Value("${app.email.max-retries:3}")
    private int maxRetries;
}

// @Profile — activate beans only in specific environments
@Configuration
@Profile("dev")
public class DevConfig {
    @Bean
    public DataSource dataSource() {
        // H2 in-memory database for development
        return new EmbeddedDatabaseBuilder()
            .setType(EmbeddedDatabaseType.H2)
            .build();
    }
}

@Configuration
@Profile("prod")
public class ProdConfig {
    @Bean
    public DataSource dataSource() {
        // Real PostgreSQL for production
        HikariDataSource ds = new HikariDataSource();
        ds.setJdbcUrl("jdbc:postgresql://db-server:5432/myapp");
        return ds;
    }
}

Quick Reference तालिका

Annotationउद्देश्यLayer
@ComponentGeneric Spring beanकोई भी
@ServiceBusiness logicService
@RepositoryData access + exception translationData
@RestControllerREST API endpoints (JSON returns)Web
@ControllerMVC endpoints (views returns)Web
@ConfigurationManually beans definesConfig
@Bean@Configuration के अंदर bean बनाता हैConfig
@ValueProperty values inject करता हैकोई भी
@ProfilePer environment beans activate करता हैConfig
@AutowiredDependencies inject करता है (constructor को prefer करें)कोई भी

N-Tier Architecture: एक Well-Run Kitchen की तरह Code Organize करना

एक professional kitchen में stations होते हैं: एक व्यक्ति सब्जियाँ prep करता है, दूसरा meat ग्रिल करता है, दूसरा खाना plate करता है। कोई भी सब कुछ नहीं करता। यह N-Tier architecture है — प्रत्येक layer का एक काम है।

Spring Boot में, standard setup तीन layers है:

HTTP Request
    |
    v
[Controller Layer]  — Takes the order (parses HTTP requests)
    |
    v
[Service Layer]     — Cooks the meal (business logic)
    |
    v
[Repository Layer]  — Gets ingredients from the pantry (database access)
    |
    v
[Database]          — The pantry (stores everything)

पूर्ण उदाहरण: Employee Management

आइए HTTP request से database और वापस तक एक पूर्ण flow बनाते हैं।

Step 1: Entity — जो database में store है

@Entity
@Table(name = "employees")
public class Employee {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(nullable = false)
    private String name;

    @Column(nullable = false, unique = true)
    private String email;

    private String department;

    // constructors, getters, setters
}

Step 2: Repository — database से बात करता है

@Repository
public interface EmployeeRepository extends JpaRepository<Employee, Long> {
    // Spring writes the SQL for you based on the method name!
    List<Employee> findByDepartment(String department);
    Optional<Employee> findByEmail(String email);
    boolean existsByEmail(String email);
}

Step 3: Service — सभी business logic शामिल है

@Service
public class EmployeeService {
    private final EmployeeRepository repository;

    public EmployeeService(EmployeeRepository repository) {
        this.repository = repository;
    }

    public List<Employee> getAllEmployees() {
        return repository.findAll();
    }

    public Employee getEmployeeById(Long id) {
        return repository.findById(id)
            .orElseThrow(() -> new ResourceNotFoundException("Employee not found with id: " + id));
    }

    public Employee createEmployee(Employee employee) {
        if (repository.existsByEmail(employee.getEmail())) {
            throw new DuplicateResourceException("Email already exists: " + employee.getEmail());
        }
        return repository.save(employee);
    }

    public Employee updateEmployee(Long id, Employee updated) {
        Employee existing = getEmployeeById(id);
        existing.setName(updated.getName());
        existing.setEmail(updated.getEmail());
        existing.setDepartment(updated.getDepartment());
        return repository.save(existing);
    }

    public void deleteEmployee(Long id) {
        Employee employee = getEmployeeById(id);
        repository.delete(employee);
    }
}

Step 4: Controller — HTTP requests को संभालता है

@RestController
@RequestMapping("/api/employees")
public class EmployeeController {
    private final EmployeeService service;

    public EmployeeController(EmployeeService service) {
        this.service = service;
    }

    @GetMapping
    public List<Employee> getAll() {
        return service.getAllEmployees();
    }

    @GetMapping("/{id}")
    public Employee getById(@PathVariable Long id) {
        return service.getEmployeeById(id);
    }

    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    public Employee create(@Valid @RequestBody Employee employee) {
        return service.createEmployee(employee);
    }

    @PutMapping("/{id}")
    public Employee update(@PathVariable Long id, @Valid @RequestBody Employee employee) {
        return service.updateEmployee(id, employee);
    }

    @DeleteMapping("/{id}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public void delete(@PathVariable Long id) {
        service.deleteEmployee(id);
    }
}

Java Records के साथ DTOs: अपने Database को बाहरी दुनिया में कभी Expose न करें

एक DTO (Data Transfer Object) एक restaurant के menu की तरह है। Kitchen में कच्चा chicken, चाकू, और ovens हैं — लेकिन आप वह सब देखना नहीं चाहते। आप एक साफ menu चाहते हैं जो केवल दिखाए कि आप क्या order कर सकते हैं।

इसी तरह, आपकी Entity में database विवरण (ID generation strategy, column constraints) हैं जो API users को नहीं देखने चाहिए। एक DTO केवल वे fields दिखाता है जिनकी उन्हें आवश्यकता है।

Java Records (Java 16+) DTOs को अविश्वसनीय रूप से साफ बनाते हैं — कोई getters, setters, equals, hashCode, या toString लिखने की आवश्यकता नहीं:

// Request DTO — what the client sends to create an employee
public record CreateEmployeeRequest(
    @NotBlank(message = "Name is required")
    String name,

    @Email(message = "Must be a valid email")
    @NotBlank(message = "Email is required")
    String email,

    String department
) {}

// Response DTO — what the client receives back
public record EmployeeResponse(
    Long id,
    String name,
    String email,
    String department,
    LocalDateTime createdAt
) {
    // Static factory method to convert Entity -> DTO
    public static EmployeeResponse from(Employee entity) {
        return new EmployeeResponse(
            entity.getId(),
            entity.getName(),
            entity.getEmail(),
            entity.getDepartment(),
            entity.getCreatedAt()
        );
    }
}

// Usage in Controller
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public EmployeeResponse create(@Valid @RequestBody CreateEmployeeRequest request) {
    Employee employee = new Employee(request.name(), request.email(), request.department());
    Employee saved = service.createEmployee(employee);
    return EmployeeResponse.from(saved);
}

@GetMapping
public List<EmployeeResponse> getAll() {
    return service.getAllEmployees().stream()
        .map(EmployeeResponse::from)
        .toList();
}

Global Exception Handling: सभी Errors के लिए एक जगह

Global exception handling के बिना, हर controller method को try-catch blocks की आवश्यकता होगी — messy और दोहराव वाला। Spring @RestControllerAdvice प्रदान करता है, जो एक safety net की तरह काम करता है जो किसी भी controller से exceptions को पकड़ता है।

इसे एक mall में customer service desk की तरह सोचें। कोई फर्क नहीं पड़ता कि आपको किस store में समस्या है, आप एक central desk पर जाते हैं जो सभी शिकायतों को संभालता है।

// Step 1: Define custom exceptions
public class ResourceNotFoundException extends RuntimeException {
    public ResourceNotFoundException(String message) {
        super(message);
    }
}

public class DuplicateResourceException extends RuntimeException {
    public DuplicateResourceException(String message) {
        super(message);
    }
}

// Step 2: Create a standard error response
public record ErrorResponse(
    int status,
    String error,
    String message,
    LocalDateTime timestamp
) {
    public static ErrorResponse of(HttpStatus status, String message) {
        return new ErrorResponse(
            status.value(),
            status.getReasonPhrase(),
            message,
            LocalDateTime.now()
        );
    }
}

// Step 3: The global exception handler — catches errors from ALL controllers
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(ResourceNotFoundException.class)
    @ResponseStatus(HttpStatus.NOT_FOUND)
    public ErrorResponse handleNotFound(ResourceNotFoundException ex) {
        return ErrorResponse.of(HttpStatus.NOT_FOUND, ex.getMessage());
    }

    @ExceptionHandler(DuplicateResourceException.class)
    @ResponseStatus(HttpStatus.CONFLICT)
    public ErrorResponse handleDuplicate(DuplicateResourceException ex) {
        return ErrorResponse.of(HttpStatus.CONFLICT, ex.getMessage());
    }

    @ExceptionHandler(MethodArgumentNotValidException.class)
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public ErrorResponse handleValidation(MethodArgumentNotValidException ex) {
        String message = ex.getBindingResult().getFieldErrors().stream()
            .map(error -> error.getField() + ": " + error.getDefaultMessage())
            .collect(Collectors.joining(", "));
        return ErrorResponse.of(HttpStatus.BAD_REQUEST, message);
    }

    @ExceptionHandler(Exception.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public ErrorResponse handleGeneral(Exception ex) {
        return ErrorResponse.of(HttpStatus.INTERNAL_SERVER_ERROR,
            "Something went wrong. Please try again later.");
    }
}

अब यदि कोई भी controller ResourceNotFoundException throw करता है, तो client को इस तरह का एक साफ JSON response मिलता है:

{
    "status": 404,
    "error": "Not Found",
    "message": "Employee not found with id: 42",
    "timestamp": "2026-04-08T10:30:00"
}

@Valid के साथ Validation: दरवाजे पर ही खराब Data को रोकें

Validation एक club में एक bouncer की तरह है। कोई भी अंदर आने से पहले, bouncer जाँच करता है: क्या आप list पर हैं? क्या आपके पास ID है? क्या आप काफी बड़े हैं? यदि कोई भी जाँच विफल होती है, तो आप अंदर नहीं आते।

Spring Boot incoming data को स्वचालित रूप से check करने के लिए Jakarta Bean Validation annotations का उपयोग करता है:

public record CreateProductRequest(
    @NotBlank(message = "Product name is required")
    @Size(min = 2, max = 100, message = "Name must be between 2 and 100 characters")
    String name,

    @NotNull(message = "Price is required")
    @Positive(message = "Price must be greater than zero")
    BigDecimal price,

    @Min(value = 0, message = "Stock cannot be negative")
    int stock,

    @NotBlank(message = "Category is required")
    String category,

    @Size(max = 500, message = "Description cannot exceed 500 characters")
    String description
) {}

// In the controller, @Valid triggers validation BEFORE your code runs
@PostMapping("/api/products")
public ProductResponse create(@Valid @RequestBody CreateProductRequest request) {
    // This code only runs if ALL validations pass
    return service.createProduct(request);
}

सामान्य Validation Annotations

Annotationक्या Check करता हैउदाहरण
@NotNullNot null (लेकिन empty हो सकता है)@NotNull Integer age
@NotBlankNot null, empty नहीं, केवल spaces नहीं@NotBlank String name
@NotEmptyNot null और empty नहीं@NotEmpty List<String> tags
@SizeRange के भीतर लंबाई@Size(min=2, max=50)
@Min / @MaxNumeric न्यूनतम / अधिकतम@Min(0) int quantity
@Positiveशून्य से अधिक@Positive BigDecimal price
@Emailवैध email format@Email String email
@Patternएक regex से match करता है@Pattern(regexp="[A-Z]{2}\\d{4}")
@Past / @FutureDate अतीत / भविष्य में@Past LocalDate birthDate

Custom Validation — जब Built-In पर्याप्त नहीं है

// Step 1: Create the annotation
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = NoProfanityValidator.class)
public @interface NoProfanity {
    String message() default "Content contains inappropriate language";
    Class<?>[] groups() default {};
    Class<? extends Payload>[] payload() default {};
}

// Step 2: Create the validator
public class NoProfanityValidator implements ConstraintValidator<NoProfanity, String> {
    private static final Set<String> BLOCKED_WORDS = Set.of("spam", "scam");

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if (value == null) return true;
        String lower = value.toLowerCase();
        return BLOCKED_WORDS.stream().noneMatch(lower::contains);
    }
}

// Step 3: Use it
public record CreateReviewRequest(
    @NoProfanity
    @NotBlank
    String comment,

    @Min(1) @Max(5)
    int rating
) {}

सब कुछ एक साथ रखना: बड़ी तस्वीर

यहाँ है कि कैसे सब कुछ जुड़ता है जब एक request आपकी Spring Boot application में hit करती है:

POST /api/employees  (JSON body: {"name": "Alice", "email": "alice@example.com"})
        |
        v
  [@Valid] Validation runs first
        |  (fails? -> GlobalExceptionHandler returns 400 Bad Request)
        v
  [EmployeeController] receives CreateEmployeeRequest DTO
        |
        v
  [EmployeeService] checks business rules (email already exists?)
        |  (duplicate? -> throws DuplicateResourceException -> handler returns 409 Conflict)
        v
  [EmployeeRepository] saves to database
        |
        v
  [EmployeeResponse DTO] returned as JSON
        |
        v
  201 Created  {"id": 1, "name": "Alice", "email": "alice@example.com"}

अक्सर पूछे जाने वाले प्रश्न

@Component, @Service, और @Repository के बीच क्या अंतर है?

कार्यात्मक रूप से, वे सभी एक ही काम करते हैं — वे Spring को एक bean बनाने और manage करने के लिए कहते हैं। अंतर intent है। @Component generic label है। @Service कहता है "इस class में business logic है।" @Repository कहता है "यह class database से बात करती है" और स्वचालित exception translation जोड़ता है (database-specific exceptions को Spring के DataAccessException में परिवर्तित करना)। इसे job titles की तरह सोचें: हर कोई एक employee है (@Component), लेकिन कुछ managers हैं (@Service) और कुछ warehouse workers (@Repository)। विशिष्ट label का उपयोग करें ताकि आपके code को पढ़ने वाला कोई भी तुरंत जान सके कि class क्या करती है।

Field injection पर constructor injection की सिफारिश क्यों की जाती है?

तीन कारण। पहला, आपकी dependencies final हो सकती हैं, जिसका अर्थ है कि वे एक बार set होती हैं और कभी नहीं बदलतीं — यह multi-threaded environments में आपकी class को सुरक्षित बनाता है। दूसरा, testing सरल है: Spring context की आवश्यकता के बिना बस constructor में mock objects pass करें। तीसरा, यदि आप एक dependency भूल जाते हैं, तो app startup पर एक स्पष्ट error message के साथ तुरंत विफल हो जाती है, runtime पर crash होने के बजाय जब कोई user code path trigger करता है। @Autowired के साथ field injection आपकी dependencies को छुपाता है और classes को test करने और reason करने के लिए कठिन बनाता है।

मुझे @Component के बजाय @Bean का उपयोग कब करना चाहिए?

आपके द्वारा लिखी गई classes के लिए @Component (या @Service, @Repository) का उपयोग करें। Third-party libraries से उन objects के लिए @Configuration class के अंदर @Bean का उपयोग करें जिन्हें आप annotate नहीं कर सकते क्योंकि आप उनके source code के owner नहीं हैं। उदाहरण के लिए, आप RestTemplate या ObjectMapper पर @Component नहीं लगा सकते क्योंकि वे external libraries से हैं। इसके बजाय, आप @Bean के साथ annotated एक method बनाते हैं जो एक configured instance return करता है, और Spring इसे वहाँ से manage करता है।

Request पर validation विफल होने पर क्या होता है?

जब आप एक @RequestBody parameter पर @Valid लगाते हैं, तो Spring आपके controller method के चलने से पहले सभी validation annotations (@NotBlank, @Email, @Size, आदि) check करता है। यदि कोई check विफल होती है, तो Spring एक MethodArgumentNotValidException throw करता है। एक global exception handler के बिना, यह एक messy 400 response returns करता है। एक @RestControllerAdvice handler (जैसा ऊपर दिखाया गया है) के साथ, आप इस exception को पकड़ सकते हैं और ठीक-ठीक बता सकते हैं कि कौन से fields विफल हुए और क्यों।

क्या मैं एक ही समय में कई profiles active रख सकता हूँ?

हाँ। आप अपने application.properties में spring.profiles.active=dev,metrics,logging set करके, एक command-line argument के रूप में (--spring.profiles.active=dev,metrics), या एक environment variable के रूप में कई profiles activate कर सकते हैं। किसी भी active profile से match करने वाले सभी beans बनाए जाएँगे। यह concerns को mix करने के लिए उपयोगी है: आपके database के लिए dev, monitoring के लिए metrics, verbose logs के लिए logging। आप production को छोड़कर हर profile में एक bean activate करने के लिए @Profile("!prod") का भी उपयोग कर सकते हैं।

More from Innovation

Innovation

इस साल बुद्धिमत्ता सस्ती हो गई — और मूल्य उस ओर खिसक गया जो आप उससे बनाते हैं

एक करोड़ AI टोकन की लागत एक ही साल में लगभग चौगुनी गिर गई। जब कच्चा माल इतनी तेज़ी से इतना सस्ता हो जाए, तो बढ़त मॉडल के मालिक होने की नहीं, बल्कि उपयोगी चीज़ बनाने वाले की होती है।

Jun 14, 20265 min read
Innovation

वह साल जब रोबोट ने प्रदर्शन करना बंद किया और काम करना शुरू किया

एक दशक तक ह्यूमनॉइड रोबोट सिर्फ़ डेमो वीडियो थे — हमेशा प्रभावशाली, हमेशा पाँच साल दूर। 2026 में कहानी चुपचाप वीडियो से उत्पादन संख्या में बदल गई। यहाँ बताया गया है कि वास्तव में क्या बदला।

Jun 14, 20265 min read
Innovation

AI हर महीने सस्ता हो रहा है। फिर सबके AI बिल क्यों फट रहे हैं?

AI की कीमत एक साल में करीब 4 गुना गिरी — जो काम $20 में होता था वह अब सेंट्स में। फिर भी कंपनियां सालभर का AI बजट महीनों में फूंक रही हैं। दोनों बातें सच हैं, और वजह समझना ज़रूरी है।

Jun 12, 20264 min read