Java Reference
In-Depth Information
Listing 2-8.
public class CarServiceImpl implements CarService{
private CarDao carDao;
public void refuel(Car car){
carDao.updateFuelConsumed(car) ;
public void setCarDao(CarDao carDao){
this.carDao = carDao;
The CarDao object is passed by the Spring IOC container using the setCarDao method. Now
you must wire things up so that Spring knows how to resolve and inject the dependency.
You can do this with a simple configuration, as shown in Listing 2-9.
Listing 2-9. spring-config.xml : Setter Injection
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
<bean name="carDao"
class="com.apress.simpleapp.dao.CatDaoImpl" />
<bean name="carService"
<property name="carDao"
ref="carDao" />
Search WWH ::

Custom Search