标签:vat stream ati ssl bean 实例 erer factor resource
解耦:
耦合包括:类之间的和方法之间的
javabean(用java语言编写的可重用组件)>实体类
/**
* Bean:可重用组件
*/
public class BeanFactory {
private static Properties props;
//静态代码块
static{
try {
//1.实例化Properties对象
props=new Properties();
//2.获取Properties文件的流对象
InputStream in = BeanFactory.class.getClassLoader().getResourceAsStream("bean.properties");
props.load(in);
}
catch (Exception e){
throw new ExceptionInInitializerError("初始化properties失败");
}
}
}
/**
* 根据bean的名称获取bean对象
* @param beanName
* @return
*/
public static Object getBean(String beanName){
Object bean = null;
try {
String beanPath = props.getProperty(beanName);
bean = Class.forName(beanPath).newInstance();
}catch (Exception e){
e.printStackTrace();
}
return bean;
}
// IAccountDao accountDao=new AccountDaoImpl();
IAccountDao accountDao = (IAccountDao) BeanFactory.getBean("accountDao");
Spring 框架的概述以及Spring中基于XML的IOC配置
标签:vat stream ati ssl bean 实例 erer factor resource
原文地址:https://www.cnblogs.com/MarkKobs-blog/p/11332397.html