public class SpringVarProducer implements VarProducer, ApplicationContextAware {
private ConfigurableApplicationContext applicationContext;
public void fill(GroovyObject groovyScript) {
ConfigurableBeanFactory beanFactory = applicationContext.getBeanFactory();
groovyScript.setProperty("applicationContext", applicationContext);
String[] beanNames = applicationContext.getBeanDefinitionNames();
for (String beanName : beanNames) {
BeanDefinition beanDef = beanFactory.getMergedBeanDefinition(beanName);
if (beanDef.isSingleton()) {
Object bean = applicationContext.getBean(beanName);
groovyScript.setProperty(beanName, bean);
}
}