spring基于xml文件的基础使用(不含对bean对象属性的设置)
1.在spring.xml中将所需类加入容器
<bean id="dao" class="huang.test.dao.imp.Dao"></bean>
2.在使用该类的类中,创建通过xml路径获取容器的对象
public class Client {
public static void main(String[] args) {
ApplicationContext applicationContext =new ClassPathXmlApplicationContext("spring.xml");
}
}
3.使用该对象即可
id即为bean的名字。
IDao dao = applicationContext.getBean("dao", IDao.class);
dao.method1();