1、导入依赖
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
2、编写配置文件
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="AccountService" class="com.itheima.service.impl.AccountServiceImpl"/>
<bean id="AccountDao" class="com.itheima.dao.impl.AccountDaoImpl"/>
</beans>
3、读取配置文件并使用
public class Client {
public static void main(String[] args) {
ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");
IAccoutDao accountDao = (IAccoutDao) ac.getBean("AccountDao");
accountDao.save();
}
}
标签:ac,accountDao,配置文件,spring,简单,IAccoutDao,使用,public
From: https://www.cnblogs.com/yanshiheng/p/17000385.html