@Test
public void test() {
Properties properties = new Properties();
properties.put("text", "hello world");
properties.put("timeout", "#{30 * 1000L}");
properties.put("random", "${random.int}");
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addLast(new PropertiesPropertySource("default", properties));
propertySources.addLast(new RandomValuePropertySource());
PropertySourcesPropertyResolver propertyResolver = new PropertySourcesPropertyResolver(propertySources);
StandardBeanExpressionResolver expressionResolver = new StandardBeanExpressionResolver();
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
SimpleTypeConverter typeConverter = new SimpleTypeConverter();
String textProp = propertyResolver.resolveRequiredPlaceholders("${text}");
Object textObj = expressionResolver.evaluate(textProp, new BeanExpressionContext(factory, null));
String text = typeConverter.convertIfNecessary(textObj, String.class);
System.out.println(text);
String timeoutProp = propertyResolver.resolveRequiredPlaceholders("${timeout}");
Object timeoutObj = expressionResolver.evaluate(timeoutProp, new BeanExpressionContext(factory, null));
Long timeout = typeConverter.convertIfNecessary(timeoutObj, Long.class);
System.out.println(timeout);
String randomProp = propertyResolver.resolveRequiredPlaceholders("${random}");
Object randomObj = expressionResolver.evaluate(randomProp, new BeanExpressionContext(factory, null));
Integer random = typeConverter.convertIfNecessary(randomObj, Integer.class);
System.out.println(random);
}