org.springframework.boot.bind.PropertiesConfigurationFactory#getObject ( )源码实例Demo

下面列出了org.springframework.boot.bind.PropertiesConfigurationFactory#getObject ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private <T> T getDruidConfig(String prefix, Class<T> claz) {
	PropertiesConfigurationFactory<T> factory = new PropertiesConfigurationFactory<T>(claz);
	factory.setPropertySources(environment.getPropertySources());
	factory.setConversionService(environment.getConversionService());
	factory.setIgnoreInvalidFields(false);
	factory.setIgnoreUnknownFields(true);
	factory.setIgnoreNestedProperties(false);
	factory.setTargetName(prefix);
	try {
		factory.bindPropertiesToTarget();
		return factory.getObject();
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
源代码2 项目: spring-boot-starter-dao   文件: GeneratorMain.java
private <T> T getDruidConfig(String prefix, Class<T> claz) {
	PropertiesConfigurationFactory<T> factory = new PropertiesConfigurationFactory<T>(claz);
	factory.setPropertySources(environment.getPropertySources());
	factory.setConversionService(environment.getConversionService());
	factory.setIgnoreInvalidFields(false);
	factory.setIgnoreUnknownFields(true);
	factory.setIgnoreNestedProperties(false);
	factory.setTargetName(prefix);
	try {
		factory.bindPropertiesToTarget();
		return factory.getObject();
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
private <T> T getPropertiesConfigurationBean(String targetName, Class<T> types) {
	PropertiesConfigurationFactory<T> factory = new PropertiesConfigurationFactory<T>(types);
	factory.setPropertySources(environment.getPropertySources());
	factory.setConversionService(environment.getConversionService());
	factory.setIgnoreInvalidFields(true);
	factory.setIgnoreUnknownFields(true);
	factory.setIgnoreNestedProperties(false);
	factory.setTargetName(targetName);
	try {
		factory.bindPropertiesToTarget();
		return factory.getObject();
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}