xml中
<bean id="userDao" class="com.wjb.dao.impl.UserDaoImpl" scope="singleton" init-method="init" destroy-method="destory"></bean>
test
package com.wjb.test; import com.wjb.dao.UserDao; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class SpringTest { @Test //测试scope属性 public void test1(){ ApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml"); UserDao userDao1 = (UserDao) app.getBean("userDao"); System.out.println(userDao1); } }