package cms.utils;
import java.io.IOException;
import java.util.Properties;
import cms.backend.dao.ArticleDao;
public class PropertiesBeanFactory implements BeanFactory {
Properties pro = new Properties();
public PropertiesBeanFactory() {
// 读取配置文件
try {
pro.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("beans.properties"));
} catch (IOException e) {
e.printStackTrace();
}
}
public ArticleDao getArtcleDao() {
String className = pro.getProperty("articleDao");
try {
Class clazz = Class.forName(className);
//new 一个对象
return (ArticleDao) clazz.newInstance();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
}