在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()
方法。
任何使用此框架的人都知道如何在现有实现中实现相同的效果?