Spring详细基本开发流程
2021-04-19 03:29
import java.io.IOException; /** public class MyFactory { public MyFactory() { public MyFactory(String config) throws IOException { // 获取对象package com.mylifes1110.factory;
import java.util.Properties;
* @ClassName MyFactory
* @Description 自定义工厂(创建对象)
* @Author Ziph
* @Date 2020/7/12
* @Since 1.8
* @Version 1.0
*/
private Properties properties = new Properties();
}
// 加载配置文件
properties.load(MyFactory.class.getResourceAsStream(config));
}
public Object getBean(String beanName) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
String classPath = properties.getProperty(beanName);
if (classPath != null) {
Class clazz = null;
clazz = Class.forName(classPath);
return clazz.newInstance();
}
return null;
}
}