使用Constretto读取属性

时间:2015-06-16 14:23:50

标签: java configuration

documentation中,作者给出了以下例子:

@Before
public void prepareTests() {
    setProperty("datasources.customer.url", "jdbc://url");
    setProperty("datasources.customer.username", "username");
    setProperty("datasources.customer.password", "password");
    setProperty("datasources.customer.vendor", "derby");
    setProperty("datasources.vendor", "derby");
    setProperty("datasources.customer.version", "10");

    configuration = new ConstrettoBuilder().createSystemPropertiesStore().getConfiguration();
}

@Test
public void createNewAnnotatedConfigurationObject() {
    DataSourceConfiguration customerDataSource = configuration.at("datasources")
        .from("customer").as(DataSourceConfiguration.class);

    assertEquals("jdbc://url", customerDataSource.getUrl());
    assertEquals("username", customerDataSource.getUsername());
    assertEquals("password", customerDataSource.getPassword());
    assertEquals("derby", customerDataSource.getVendor());
    assertEquals(new Integer(10), customerDataSource.getVersion());
}

但是,ConstrettoConfiguration类似乎没有at()from()方法。

任何使用此框架的人都知道如何在现有实现中实现相同的效果?

0 个答案:

没有答案