代码示例:
public interface UserDao {
}
-------------------------------------------------------------
public class UserDaoImpl implements UserDao {
}
----------------------------------------------------------
public interface UserService {
}
---------------------------------------------------------
public class UserServiceImpl implements UserService {
private UserDao userDao;
//该方法是Bean工厂去调用的,从工厂当中获得userDao设置到此处
public void setUserDao(UserDao userDao) {
this.userDao = userDao;
System.out.println(userDao);
}
}
----------------------------------------------------------
public class ApplicationContextTest {
public static void main(String[] args) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
UserService userService = (UserService) applicationContext.getBean("userService");
System.out.println(userService);
}
}
标签:ApplicationContext,UserDao,入门,applicationContext,spring,UserService,userDao,publ From: https://www.cnblogs.com/gagaya2/p/17801265.html