play加载application.conf和加载mybatis的configuration.xml流程

application.conf作为play框架的配置文件,里面配置了各种属性,那么当框架运行的时候,到底是怎么去加载的呢?

刚看了下它的代码,它是在Play类中定义了一个静态变量 public static Properties configuration;

然后其中使用  readConfiguration() 去读取配置文件

public static void readConfiguration() {
        configuration = readOneConfigurationFile("application.conf", new HashSet<String>());
        // Plugins
        pluginCollection.onConfigurationRead();
    }

读取完 application.conf配置文件,configuration进行了初始化,然后通过 configuration.getProperty()方法,来获取配置中的属性

  private SqlSessionFactory getSqlSessionFactory() {
        if (sessionFactory == null) {
            String resource = Play.configuration.getProperty("mybatis.configuration");
            Reader reader;

            try {
                reader = Resources.getResourceAsReader(resource);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }

            Properties prop = new Properties();

            prop.put("url", Play.configuration.getProperty("db.url"));
            prop.put("user", Play.configuration.getProperty("db.user"));
            prop.put("pass", Play.configuration.getProperty("db.pass"));
            prop.put("driver", Play.configuration.getProperty("db.driver"));

            sessionFactory = new SqlSessionFactoryBuilder().build(reader, prop);

        }

        return sessionFactory;
    }
View Code

其中会根据该语句 

String resource = Play.configuration.getProperty("mybatis.configuration");

Reader reader;

reader = Resources.getResourceAsReader(resource);

去加载mybatis的配置文件,configuration.xml,大致就是这样子吧,我觉得

转载于:https://www.cnblogs.com/genpys/p/4304879.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值