Skip to content

Prakharpanchal7240/MixedInjection-SpringCore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Spring Core - Mixed Dependency Injection

This project demonstrates Mixed Dependency Injection in the Spring Framework using XML Configuration.

The project consists of two classes:

  • Manager – Created using Constructor Injection
  • Project – Receives the Manager object through Constructor Injection, while its own properties (projectName and duration) are initialized using Setter Injection.

This example illustrates how constructor and setter injection can be combined in a real-world scenario.


🚀 Features

  • Spring IoC Container
  • XML-based Bean Configuration
  • Constructor Injection
  • Setter Injection
  • Reference Type Injection
  • Mixed Dependency Injection
  • Maven Project

🛠️ Technologies Used

  • Java
  • Spring Core
  • Maven
  • XML

📂 Project Structure

SpringCore-MixedInjection
│
├── src
│   └── main
│       ├── java
│       │   ├── com
│       │   │   └── configuration
│       │   │       └── application-context.xml
│       │   │
│       │   └── springcore
│       │       └── SetterAndConstructorInjection
│       │           ├── App.java
│       │           ├── Project.java
│       │           └── Manager.java
│       │
│       └── resources
│
├── pom.xml
├── README.md
└── .gitignore

XML Configuration

Manager Bean (Constructor Injection)

<bean id="manager" class="springcore.SetterAndConstructorInjection.Manager">

    <constructor-arg value="Ravi Shankar"/>
    <constructor-arg value="IT"/>

</bean>

Project Bean (Mixed Injection)

<bean id="project" class="springcore.SetterAndConstructorInjection.Project">

    <constructor-arg ref="manager"/>

    <property name="projectName" value="Employee Management System"/>
    <property name="duration" value="6 Months"/>

</bean>

Output

Project [
    projectName=Employee Management System,
    duration=6 Months,
    manager=Manager [managerName=Ravi Shankar, department=IT]
]

Concepts Covered

  • Spring IoC Container
  • Dependency Injection
  • Constructor Injection
  • Setter Injection
  • Reference Type Injection
  • Mixed Dependency Injection
  • XML Bean Configuration

Author

Prakhar Panchal

About

Spring Core project demonstrating mixed dependency injection using Setter Injection for primitive properties and Constructor Injection for reference type with XML configuration.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages