in jetcache-starter/jetcache-autoconfigure/src/main/java/com/alicp/jetcache/autoconfigure/RedisAutoConfiguration.java [164:209]
private GenericObjectPoolConfig parsePoolConfig(ConfigTree ct) {
try {
// Spring Boot 2.0 removed RelaxedDataBinder class. Binder class not exists in 1.X
if (ClassUtils.isPresent("org.springframework.boot.context.properties.bind.Binder",
this.getClass().getClassLoader())) {
// Spring Boot 2.0+
String prefix = ct.subTree("poolConfig").getPrefix().toLowerCase();
// invoke following code by reflect
// Binder binder = Binder.get(environment);
// return binder.bind(name, Bindable.of(GenericObjectPoolConfig.class)).get();
Class<?> binderClass = Class.forName("org.springframework.boot.context.properties.bind.Binder");
Class<?> bindableClass = Class.forName("org.springframework.boot.context.properties.bind.Bindable");
Class<?> bindResultClass = Class.forName("org.springframework.boot.context.properties.bind.BindResult");
Method getMethodOnBinder = binderClass.getMethod("get", Environment.class);
Method getMethodOnBindResult = bindResultClass.getMethod("get");
Method bindMethod = binderClass.getMethod("bind", String.class, bindableClass);
Method ofMethod = bindableClass.getMethod("of", Class.class);
Object binder = getMethodOnBinder.invoke(null, environment);
Object bindable = ofMethod.invoke(null, GenericObjectPoolConfig.class);
Object bindResult = bindMethod.invoke(binder, prefix, bindable);
return (GenericObjectPoolConfig) getMethodOnBindResult.invoke(bindResult);
} else {
// Spring Boot 1.X
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
Map<String, Object> props = ct.subTree("poolConfig.").getProperties();
// invoke following code by reflect
//RelaxedDataBinder binder = new RelaxedDataBinder(poolConfig);
//binder.bind(new MutablePropertyValues(props));
Class<?> relaxedDataBinderClass = Class.forName("org.springframework.boot.bind.RelaxedDataBinder");
Class<?> mutablePropertyValuesClass = Class.forName("org.springframework.beans.MutablePropertyValues");
Constructor<?> c1 = relaxedDataBinderClass.getConstructor(Object.class);
Constructor<?> c2 = mutablePropertyValuesClass.getConstructor(Map.class);
Method bindMethod = relaxedDataBinderClass.getMethod("bind", PropertyValues.class);
Object binder = c1.newInstance(poolConfig);
bindMethod.invoke(binder, c2.newInstance(props));
return poolConfig;
}
} catch (Throwable ex) {
throw new CacheConfigException("parse poolConfig fail", ex);
}
}