public class DaoFactory {
    private static Properties pro = new Properties();
    static {
        try {
            pro.load(new FileReader("dao.txt"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static Object getBean(String interfaceName) {
        //根据键,得到值
        String value = pro.getProperty(interfaceName);
        try {
            //加载类  得到类模板
            Class c = Class.forName(value);
            //调用无参构造方法,产生实现类对象
            return c.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}

 

 

 

相关文章:

  • 2021-07-25
  • 2021-09-22
  • 2021-10-03
  • 2021-10-05
  • 2022-01-08
  • 2019-01-20
  • 2021-06-08
猜你喜欢
  • 2022-12-23
  • 2021-05-17
  • 2022-12-23
  • 2021-11-17
  • 2021-06-03
  • 2021-08-08
  • 2021-04-13
相关资源
相似解决方案