DEV Community

Hunor Vadasz-Perhat
Hunor Vadasz-Perhat

Posted on

๐Ÿ“Œ spring-note-001: Introduction to Spring Framework

๐Ÿ”น What is Spring Framework?

โœ… Spring is a Java-based framework that simplifies application development.

โœ… It provides comprehensive infrastructure support for enterprise applications.

โœ… Spring allows developers to focus on business logic while handling common concerns like:

  • Dependency Injection (DI)
  • Transaction Management
  • Security
  • Web Development
  • Messaging & Event Handling

๐Ÿ’ก Think of Spring as a Swiss Army knife ๐Ÿ› ๏ธ for Java development!


๐Ÿ”น Why Does Spring Exist? What Problem Does It Solve?

Before Spring, Java EE (Enterprise Edition) applications were complicated, rigid, and full of boilerplate code ๐Ÿ˜ต.

๐Ÿ”ฅ Spring solves these problems by:

โœ… Reducing Boilerplate Code โ†’ No need to manually manage transactions, security, or object creation.

โœ… Providing an IoC (Inversion of Control) Container โ†’ Spring manages object lifecycles for you.

โœ… Simplifying Web & Data Access โ†’ Spring Boot + Spring Data = Rapid development.

โœ… Supporting Multiple Architectures โ†’ Works for monoliths, microservices, event-driven apps, etc.

โœ… Being Modular โ†’ Use only the parts you need (DI, Web, Security, etc.).

๐Ÿ’ก In short: Spring makes Java development EASIER, FASTER, and MORE FLEXIBLE.


๐Ÿ”น Key Features of Spring

๐Ÿš€ Spring Core โ†’ Provides IoC Container & Dependency Injection (DI)

๐ŸŒ Spring Web โ†’ Supports MVC & REST API development

๐Ÿ’พ Spring Data โ†’ Simplifies JDBC, JPA, and NoSQL interactions

๐Ÿ” Spring Security โ†’ Handles authentication, authorization, and OAuth2

๐Ÿ› ๏ธ Spring Boot โ†’ Makes Spring setup fast & automatic

๐Ÿ“ก Spring Cloud โ†’ Supports microservices & distributed applications

๐Ÿ”ฅ Spring isnโ€™t just a frameworkโ€”itโ€™s an ECOSYSTEM! ๐Ÿ—๏ธ


๐Ÿ“Œ Hands-On Project: Small Spring Boot Starter

๐Ÿ’ก Letโ€™s create a simple Spring Boot app to experience Spring in action.

Step 1: Create a Spring Boot Project

1๏ธโƒฃ Go to Spring Initializr

2๏ธโƒฃ Select:

  • Spring Boot Version: Latest stable
  • Dependencies: Spring Web, Spring Boot Actuator
  • Packaging: Jar 3๏ธโƒฃ Click Generate and extract the zip file.

Step 2: Create a Simple REST API

๐Ÿš€ Modify the main application class:

package com.example.springintro;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringIntroApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringIntroApplication.class, args);
    }
}
Enter fullscreen mode Exit fullscreen mode

๐Ÿ’ก Spring Boot automatically configures and runs the application. ๐ŸŽ‰


Step 3: Add a REST Controller

๐Ÿ“Œ Create a simple API endpoint using Spring Web:

package com.example.springintro.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class HelloController {

    @GetMapping("/hello")
    public String sayHello() {
        return "Ahoy, Captain! Welcome to the Spring World! โš“๐Ÿ”ฅ";
    }
}
Enter fullscreen mode Exit fullscreen mode

Step 4: Run the Application

๐Ÿ’ก Run the app using:

mvn spring-boot:run
Enter fullscreen mode Exit fullscreen mode

or

./mvnw spring-boot:run
Enter fullscreen mode Exit fullscreen mode

๐ŸŒ Visit: http://localhost:8080/api/hello

๐ŸŽ‰ You should see:

Ahoy, Captain! Welcome to the Spring World! โš“๐Ÿ”ฅ
Enter fullscreen mode Exit fullscreen mode

๐Ÿ“Œ Summary

โœ… Spring simplifies Java development by managing dependencies, security, and transactions.

โœ… It follows a modular approachโ€”you only use what you need.

โœ… Spring Boot makes it even easier by handling configurations automatically.

โœ… A simple REST API can be created in just a few lines of code!


๐Ÿ“Œ Topics Covered in This Section
๐Ÿ“œ Spring Core Concepts (โœ”๏ธ Covered)

  • Purpose of Spring, solving Java EE complexities.
  • Core modules: DI, Web, Data, Security, Boot, Cloud.

๐Ÿ› ๏ธ Spring Boot Basics (โœ”๏ธ Covered)

  • Spring Boot auto-configuration.
  • Creating a simple REST API with Spring Web.
  • Running a Spring Boot app (SpringApplication.run()).

๐Ÿ’ก Key Takeaways to Remember:
โœ… Spring provides infrastructure support for enterprise applications.
โœ… Spring's core feature is IoC (Dependency Injection).
โœ… Spring Boot simplifies application setup & config.
โœ… Spring modules work independentlyโ€”you use only what you need.

Top comments (0)