Spring入门之Bean实例化的三种方法
作者:互联网
无参构造
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); } }
标签:UserDao,入门,Spring,app,userDao1,Bean,import,Test,org 来源: https://www.cnblogs.com/wjingbo/p/16422992.html