A demonstration project showcasing core Spring Framework concepts, focusing on Dependency Injection, Loose Coupling, and Tight Coupling patterns in Java applications.
- About
- Project Structure
- Technologies Used
- Key Concepts
- Prerequisites
- Installation
- Running the Application
- Package Descriptions
- Author
- License
This project is designed to help developers understand fundamental Spring Framework concepts through practical examples. It demonstrates:
- The difference between Tight Coupling and Loose Coupling
- How Spring's Dependency Injection promotes loose coupling
- Configuration using XML-based ApplicationContext
- Real-world examples comparing coupled vs decoupled architectures
spring_core/
├── .idea/ # IntelliJ IDEA configuration files
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── com/
│ │ │ ├── ayish.spring_core/ # Core Spring examples
│ │ │ ├── example.demo/ # Demo examples
│ │ │ ├── LooseCoupling/ # Loose coupling examples
│ │ │ └── TightCoupling/ # Tight coupling examples
│ │ └── resources/
│ │ ├── archetype-resources/
│ │ ├── META-INF/
│ │ │ └── maven/
│ │ └── ApplicationBeanContext.xml # Spring Bean Configuration
│ └── test/ # Test files
├── target/ # Compiled output
├── .gitignore
├── pom.xml # Maven configuration
└── README.md
| Technology | Version | Purpose |
|---|---|---|
| Java | 8+ | Core programming language |
| Spring Framework | 5.x/6.x | Dependency Injection & IoC Container |
| Maven | 3.6+ | Build automation and dependency management |
| IntelliJ IDEA | - | IDE for development |
In tight coupling, classes are directly dependent on concrete implementations. Changes in one class require changes in dependent classes.
Example:
// Classes directly instantiate their dependencies
public class UserService {
private UserRepository repository = new UserRepository();
// If UserRepository changes, UserService must change
}In loose coupling, classes depend on abstractions (interfaces) rather than concrete implementations. This makes the code more flexible and maintainable.
Example:
// Classes depend on interfaces
public class UserService {
private IUserRepository repository;
// Dependency is injected, not created
public UserService(IUserRepository repository) {
this.repository = repository;
}
}Spring's Inversion of Control (IoC) container manages object creation and dependency injection through the ApplicationContext, configured via XML or annotations.
Before running this project, ensure you have:
- JDK 8 or higher installed
- Maven 3.6+ installed
- IntelliJ IDEA (recommended) or any Java IDE
- Git (for cloning the repository)
-
Clone the repository
git clone https://github.com/Ayish-Shaikh/spring_core.git
-
Navigate to the project directory
cd spring_core -
Import as Maven project
- Open IntelliJ IDEA
- Select File → Open
- Choose the
pom.xmlfile - Import as a Maven project
-
Build the project
mvn clean install
- Open the project in IntelliJ IDEA
- Navigate to the main class (typically in
com.ayish.spring_corepackage) - Right-click on the main class
- Select Run 'MainClass.main()'
mvn exec:java -Dexec.mainClass="com.ayish.spring_core.MainClass"# Compile
javac -cp target/classes src/main/java/com/ayish/spring_core/*.java
# Run
java -cp target/classes com.ayish.spring_core.MainClassContains core Spring configuration and main application classes demonstrating Spring IoC container usage.
Includes demo examples and utility classes for understanding Spring concepts.
Demonstrates loose coupling principles where:
- Dependencies are injected via constructors or setters
- Classes depend on interfaces, not concrete implementations
- Spring manages object lifecycle and dependencies
Shows tight coupling anti-patterns where:
- Objects create their own dependencies
- Hard-coded dependencies make testing difficult
- Changes ripple through the codebase
XML configuration file that defines Spring beans and their dependencies. This file:
- Declares beans managed by Spring IoC container
- Configures dependency injection
- Sets up application context
After exploring this project, you will understand:
- ✅ The problems with tight coupling
- ✅ Benefits of loose coupling and dependency injection
- ✅ How to configure Spring beans using XML
- ✅ How Spring's IoC container manages dependencies
- ✅ Best practices for designing maintainable Java applications
Contributions are welcome! To contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Ayish Shaikh
- GitHub: @Ayish-Shaikh
- Repository: spring_core
This project is open source and available under the MIT License.
- Spring Framework Documentation
- Spring Core Concepts
- Dependency Injection Explained
- Maven Documentation
- Spring Framework Community
- Java Community
⭐ If you find this project helpful, please consider giving it a star!