src/org/bs/utils/PropertiesBeanFactory.java

(完整代码) 967B

package org.bs.utils;

import java.io.InputStream;
import java.util.Properties;

public class PropertiesBeanFactory<T> implements BeanFactory {

	private static Properties props =  new Properties();
	static {
		InputStream inputStream = PropertiesBeanFactory.class.getClassLoader().getResourceAsStream("beans.properties");
		try {
			props.load(inputStream);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public T getBean(String beanName) {
		String className = props.getProperty(beanName);
		T bean = null;
		if(beanName.indexOf("Service")>-1){
			JDBCHandler<T> jdbcHandler = new JDBCHandler<T>();
			try {
				T temp = (T)Class.forName(className).newInstance();
				bean = jdbcHandler.createProxy(temp);
			} catch (Exception e) {
				e.printStackTrace();
			} 
		}else{
			try {
				bean = (T)Class.forName(className).newInstance();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return bean;
	}
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。