Introduction to Spring Framework
All Java Topics
Last updated: May 25, 2026
Author: ManaCoding Team
Spring Framework is a powerful, lightweight, and widely used Java framework for building enterprise-level applications. It provides features like dependency injection, aspect-oriented programming, and web development support.
Syntax
@Configuration
@ComponentScan(basePackages = "com.example")
public class AppConfig {
}
Example Program
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan(basePackages = "com.example")
class AppConfig {
}
class HelloService {
public void sayHello() {
System.out.println("Hello from Spring Framework");
}
}
public class Main {
public static void main(String[] args) {
ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
HelloService service = context.getBean(HelloService.class);
service.sayHello();
}
}
// Output:
// Hello from Spring Framework
What is Spring Framework?
- 1 A lightweight Java framework.
- 2 Used for enterprise applications.
- 3 Provides dependency injection.
- 4 Supports web and microservices development.
Core Features
- 1 Dependency Injection (DI).
- 2 Aspect-Oriented Programming (AOP).
- 3 Spring MVC for web apps.
- 4 Transaction management.
Why Use Spring?
- 1 Reduces boilerplate code.
- 2 Improves scalability.
- 3 Supports modular development.
- 4 Highly flexible and extensible.
Spring Ecosystem
- 1 Spring Boot – rapid development.
- 2 Spring MVC – web framework.
- 3 Spring Data – database access.
- 4 Spring Security – authentication & authorization.
Quick Summary
- Spring is a lightweight Java framework.
- It provides dependency injection and modular architecture.
- Used in enterprise and microservices applications.
- Spring Boot simplifies configuration.
FAQs
What is Spring Framework?
It is a Java framework used for building enterprise applications.
What are core features of Spring?
Dependency Injection, AOP, MVC, and transaction management.
Why use Spring Framework?
To reduce boilerplate code and improve scalability.
What is Spring Boot?
It is a project that simplifies Spring application development.
Is Spring lightweight?
Yes, it is designed to be lightweight and modular.
Interview Questions
Q1.
What is Spring Framework?
Answer:
It is a Java framework used for building enterprise applications.
Q2.
What are core features of Spring?
Answer:
Dependency Injection, AOP, MVC, and transaction management.
Q3.
Why use Spring Framework?
Answer:
To reduce boilerplate code and improve scalability.
Q4.
What is Spring Boot?
Answer:
It is a project that simplifies Spring application development.
Q5.
Is Spring lightweight?
Answer:
Yes, it is designed to be lightweight and modular.
Quiz
What is Spring Framework mainly used for?