package ioc1.it.dao; public class userDaoImpl implements userDao { public userDaoImpl() { System.out.println("无参"); } @Override public void save() { System.out.println("kachaq"); } }
private userDao userDao; public void setUserDao(ioc1.it.dao.userDao userDao) { this.userDao = userDao; } public void save(){ userDao.save(); }
<bean id="userDao" class="ioc1.it.dao.userDaoImpl"></bean> <bean id="service" class="factory.service"> <property name="userDao" ref="userDao"></property> </bean>
public static void main(String[] args) { ClassPathXmlApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml"); service service = (service)app.getBean("service"); service.save(); }