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()方法,来获取配置中的属性
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
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; }
其中会根据该语句
String resource = Play.configuration.getProperty("mybatis.configuration");
Reader reader;
reader = Resources.getResourceAsReader(resource);
去加载mybatis的配置文件,configuration.xml,大致就是这样子吧,我觉得