Spring Dependency Injection using XML Configuration

The below example describes Spring Dependency Injection using XML.

1. Project Setup

Lets create a simple maven project with the below pom.xml

2. Code Interface

Code an Interface say

3. Code Implementation

add an Implementation to the above Interface

4. Configure Spring & Declare Bean

Define the above bean in applicationContext.xml as below

5. Main Program

The main program to test would be

6. Output:

Output

Output

7. Project Structure:

Project Structure

Project Structure

Download-Spring-Maven-Project

I hope this has been useful for you and Iā€™d like to thank you for reading. If you like this article, please leave a helpful comment and share it with your friends.

Comments

  1. By Sundar

    Reply

    • By Manjunath

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *