<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Divya Ojha</title>
    <description>The latest articles on DEV Community by Divya Ojha (@thedivyaojha).</description>
    <link>https://dev.to/thedivyaojha</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3561038%2F85ec940d-8a2c-4317-b631-12832cd841a5.png</url>
      <title>DEV Community: Divya Ojha</title>
      <link>https://dev.to/thedivyaojha</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thedivyaojha"/>
    <language>en</language>
    <item>
      <title>Spring Framework Explained Simply: Why It Finally Made Sense to Me published</title>
      <dc:creator>Divya Ojha</dc:creator>
      <pubDate>Sun, 12 Oct 2025 19:29:01 +0000</pubDate>
      <link>https://dev.to/thedivyaojha/spring-framework-explained-simply-why-it-finally-made-sense-to-mepublished-2lpa</link>
      <guid>https://dev.to/thedivyaojha/spring-framework-explained-simply-why-it-finally-made-sense-to-mepublished-2lpa</guid>
      <description>&lt;p&gt;The Problem With Traditional Java&lt;br&gt;
When I first started learning backend development, I kept hearing: “Just use Spring.” But honestly? The concepts sounded terrifying. IoC, DI, Beans — it felt like a wall of jargon I’d never understand.&lt;/p&gt;

&lt;p&gt;Then I actually tried building something without a framework. That’s when I got it.&lt;/p&gt;

&lt;p&gt;Here’s what building a simple REST API looks like without Spring:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class EmployeeService {
    private EmployeeDAO employeeDAO;

    public EmployeeService() {
        // Manually creating dependencies
        DatabaseConnection dbConn = new DatabaseConnection(
            "jdbc:mysql://localhost:3306/mydb", 
            "root", 
            "password"
        );
        this.employeeDAO = new EmployeeDAO(dbConn);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Problems:&lt;/p&gt;

&lt;p&gt;Every class manually creates its dependencies&lt;br&gt;
Can’t test without a real database&lt;br&gt;
Change database credentials? Update 20 files&lt;br&gt;
Objects are tightly coupled — hard to maintain&lt;br&gt;
This is where Spring comes in.&lt;/p&gt;

&lt;p&gt;What Actually Is Spring?&lt;br&gt;
Spring Framework is a collection of tools that handles all the repetitive infrastructure code — object creation, configuration, database connections — so you can focus on building features.&lt;/p&gt;

&lt;p&gt;Think of it like this:&lt;/p&gt;

&lt;p&gt;Without frameworks: Build a house by cutting trees, making bricks, mixing cement&lt;br&gt;
With Spring: Assemble pre-made walls, doors, and plumbing&lt;br&gt;
Spring was created in 2002 by Rod Johnson to simplify enterprise Java development, which was notoriously complex at the time.&lt;/p&gt;

&lt;p&gt;The Three Core Concepts (Simplified)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Inversion of Control (IoC)
In simple terms: Instead of YOU creating objects, Spring creates them for you.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Traditional way:&lt;/p&gt;

&lt;p&gt;EmployeeService service = new EmployeeService(); // You control creation&lt;br&gt;
Spring way:&lt;/p&gt;

&lt;p&gt;@Autowired&lt;br&gt;
private EmployeeService service; // Spring controls creation&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Dependency Injection (DI)
In simple terms: Spring automatically passes (injects) the objects your class needs.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Service
public class EmployeeService {
    private final EmployeeDAO dao;

    // Spring injects EmployeeDAO here
    public EmployeeService(EmployeeDAO dao) {
        this.dao = dao;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;No manual object creation. No tight coupling. Easy to test.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Beans
In simple terms: A Bean is just an object that Spring manages.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
@Service  // This is a Bean
public class EmployeeService { }
@Repository  // This is also a Bean
public class EmployeeDAO { }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Spring creates these at startup and injects them wherever needed.&lt;/p&gt;

&lt;p&gt;The Magic of Auto-Configuration&lt;br&gt;
The feature that made me fall in love with Spring? Spring Boot’s auto-configuration.&lt;/p&gt;

&lt;p&gt;Look at this — a complete web application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@SpringBootApplication
public class MyApp {
    public static void main(String[] args) {
        SpringApplication.run(MyApp.class, args);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This automatically:&lt;/p&gt;

&lt;p&gt;Starts a web server&lt;br&gt;
Configures Spring&lt;br&gt;
Scans for components&lt;br&gt;
Sets up defaults&lt;br&gt;
Want a database? Add one dependency and Spring configures it automatically. No XML, no endless setup.&lt;/p&gt;

&lt;p&gt;Real Example: Building a REST API&lt;br&gt;
Without Spring (~200 lines of configuration)&lt;br&gt;
You’d manually configure servlets, parse JSON, handle exceptions, manage transactions…&lt;/p&gt;

&lt;p&gt;With Spring Boot (~20 lines)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@RestController
@RequestMapping("/api/employees")
public class EmployeeController {

    @Autowired
    private EmployeeService service;

    @GetMapping("/{id}")
    public Employee getEmployee(@PathVariable int id) {
        return service.getEmployee(id);
    }

    @PostMapping
    public Employee createEmployee(@RequestBody Employee employee) {
        return service.saveEmployee(employee);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spring automatically:&lt;/p&gt;

&lt;p&gt;Maps URLs to methods&lt;br&gt;
Converts JSON ↔ Java objects&lt;br&gt;
Handles HTTP status codes&lt;br&gt;
Manages database transactions&lt;br&gt;
Why Testing Is a Game Changer&lt;br&gt;
Here’s what blew my mind when I started writing tests:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@SpringBootTest
class EmployeeServiceTest {

    @MockBean
    private EmployeeRepository repository;

    @Autowired
    private EmployeeService service;

    @Test
    void testGetEmployee() {
        // Mock data—no real database needed!
        Employee mock = new Employee(1, "John");
        when(repository.findById(1)).thenReturn(Optional.of(mock));

        Employee result = service.getEmployee(1);
        assertEquals("John", result.getName());
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can test business logic without touching the database. Components are isolated. This is the power of loose coupling.&lt;/p&gt;

&lt;p&gt;The Spring Ecosystem&lt;br&gt;
Once you learn Spring basics, you unlock powerful modules:&lt;/p&gt;

&lt;p&gt;Module Purpose Spring Boot Rapid setup with auto-configuration Spring Data Database access without writing SQL Spring Security Authentication &amp;amp; authorization Spring Cloud Build microservices (Netflix uses this)&lt;/p&gt;

&lt;p&gt;Spring Data Example&lt;br&gt;
Without Spring Data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
String sql = "SELECT * FROM employees WHERE department = ?";
PreparedStatement stmt = conn.prepareStatement(sql);
// ... 20+ lines of boilerplate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With Spring Data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface EmployeeRepository extends JpaRepository&amp;lt;Employee, Integer&amp;gt; {
    List&amp;lt;Employee&amp;gt; findByDepartment(String department);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spring generates the implementation at runtime. That’s it.&lt;/p&gt;

&lt;p&gt;Try It Yourself (5 Minutes)&lt;br&gt;
Go to start.spring.io&lt;br&gt;
Select “Spring Web”&lt;br&gt;
Download and unzip&lt;br&gt;
Create a controller:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@RestController
public class HelloController {
    @GetMapping("/hello")
    public String hello(@RequestParam(defaultValue = "World") String name) {
        return "Hello, " + name + "!";
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run: mvn spring-boot:run&lt;br&gt;
Visit: &lt;a href="http://localhost:8080/hello" rel="noopener noreferrer"&gt;http://localhost:8080/hello&lt;/a&gt;&lt;br&gt;
You just built a web server with zero configuration.&lt;/p&gt;

&lt;p&gt;Should You Learn Spring?&lt;br&gt;
Yes, if:&lt;/p&gt;

&lt;p&gt;You’re building Java web applications&lt;br&gt;
You want to become a Java backend developer&lt;br&gt;
You value clean, testable code&lt;br&gt;
You’re job hunting (60% of Java jobs require Spring)&lt;br&gt;
Maybe not, if:&lt;/p&gt;

&lt;p&gt;You’re building tiny scripts&lt;br&gt;
You want absolute control over everything&lt;br&gt;
You prefer ultra-lightweight frameworks&lt;br&gt;
How Spring’s Core Concepts Connect&lt;/p&gt;

&lt;p&gt;How it flows:&lt;/p&gt;

&lt;p&gt;IoC Container scans for @Component, @Service, @Repository annotations&lt;br&gt;
Creates all Beans and stores them in its container&lt;br&gt;
When Controller needs Service, DI injects it automatically&lt;br&gt;
When Service needs DAO, DI injects that too&lt;br&gt;
You just write business logic — Spring handles the wiring&lt;br&gt;
The Bottom Line&lt;br&gt;
Spring isn’t complicated — it’s just unfamiliar. Once you understand:&lt;/p&gt;

&lt;p&gt;IoC — Spring creates objects&lt;br&gt;
DI — Spring passes objects where needed&lt;br&gt;
Beans — Objects managed by Spring&lt;br&gt;
…everything else clicks into place.&lt;/p&gt;

&lt;p&gt;The framework exists to handle boring infrastructure so you can focus on building features. That’s it.&lt;/p&gt;

&lt;p&gt;Resources to Get Started&lt;br&gt;
Spring Boot Official Guides&lt;br&gt;
EmbarkX YouTube Channel&lt;br&gt;
Spring Documentation&lt;br&gt;
Spring Initializr&lt;br&gt;
Got questions about Spring? Drop them below — I’d love to help you get past that initial learning curve.&lt;/p&gt;

&lt;p&gt;Lets connect — &lt;a class="mentioned-user" href="https://dev.to/thedivyaojha"&gt;@thedivyaojha&lt;/a&gt;❤️…&lt;/p&gt;

</description>
      <category>java</category>
      <category>spring</category>
      <category>springboot</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
