<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- 配置工厂 -->
<bean/>
<!-- 使用factory-bean属性配置一个实例工厂,使用factory-method属性确定工厂中的哪个方法 -->
<bean factory-bean="myBeanFactory" factory-method="createUserDao"/>
</beans>
好像只有这些代码和xml配置文件无法运行啊,缺少主函数,看看我们的Client主函数,主函数内代码如下:
public class Client {
public static void main(String[] args) {
// TODO Auto-generated method stub
//此处定义xml文件放置的位置为src目录下的com/xml目录下
String path = "com/xml/bean.xml";
ApplicationContext application = new ClassPathXmlApplicationContext(path);
UserDaoImpl userDao = (UserDaoImpl) application.getBean("userDao");
userDao.sayHello(); //调用UserDaoImpl类的sayHello方法
}
}