Spring with xml configuration file

In this example, we will see how you make dependency with the XML configuration file. First I am going to create the class Car withe dependancy Engine .
So your Car class would be like this

This is the dependant class Engine

Next you can create the configuration file bean.xml

When you look at the XML file you can see the I have created the withe ref which points to bean having the id with engine. So we tell to spring that Engine is dependant class of the Car class

Now we can create the bean using context

When you run the application you can see the following output

Alternatively, you can use the followng configuration file