<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="accountDao" class="dao.impl.AccountDaoImpl"></bean> </beans>
测试方法
获取ApplicationContext对象的三种方式
//从文件系统获取,填写在硬盘上的绝对路径
FileSystemXmlApplicationContext("bean.xml");
AnnotationConfigApplicationContext("");
ClassPathXmlApplicationContext("bean.xml");
public static void main(String[] args) {
        //读取配置文件
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("bean.xml");
        //根据配置的id获取指定对象
        AccountDao accountDao = applicationContext.getBean("accountDao",AccountDao.class);
        //测试方法
        accountDao.saveAccount();
    }
原文:https://www.cnblogs.com/ushowtime/p/12198737.html