I have class Employee which is singleton as defined in spring.xml
public class Employee{
private Vehicle vehicle;
public Vehicle getVehicle() {
return vehicle;
}
public void setVehicle(Vehicle vehicle) {
this.vehicle = vehicle;
}
}
I have class Vehicle which is prototype as defined in spring.xml
public class Vehicle {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Below is spring.xml
<bean id="employee" class="com.example.factory.Employee">
<property name="vehicle" ref="vehicle"></property>
</bean>
<bean id="vehicle" class="com.example.factory.Vehicle" scope="prototype">
<property name="name" value="car"></property>
<aop:scoped-proxy />
</bean>
Now I know spring will create proxy for vehicle. Every time I call getVehicle() on employee object I get new object of Vehicle. But in getVehicle() method I am not creating new object of Vehicle and as per my understanding spring is not creating proxy for Employee object. So someone please make me understand in detail what is happening internally and how getVehicle() is working?