/**
* bean的作用域
*/
public class Test05 {
public static void main(String[] args) {
ApplicationContext ac = new ClassPathXmlApplicationContext("bean的作用域.xml");
UserDao userDao1 = (UserDao) ac.getBean("userDao1");
UserDao userDao2 = (UserDao) ac.getBean("userDao1");
System.out.println(userDao1);
System.out.println(userDao2);
System.out.println(userDao1 == userDao2);
System.out.println("==============================");
UserDao userDao3 = (UserDao) ac.getBean("userDao2");
System.out.println(userDao3);
UserDao userDao4 = (UserDao) ac.getBean("userDao2");
System.out.println(userDao4);
System.out.println(userDao3 == userDao4);
}
}
输出结果
实例化UserDaoImpl…
com.sy.dao.impl.UserDaoImpl@204f30ec
com.sy.dao.impl.UserDaoImpl@204f30ec
true
实例化UserDaoImpl…
com.sy.dao.impl.UserDaoImpl@e25b2fe
实例化UserDaoImpl…
com.sy.dao.impl.UserDaoImpl@754ba872
false