try {
Thread.currentThread().setContextClassLoader(BrokerService.class.getClassLoader());
Resource resource = Utils.resourceFromString(config);
ResourceXmlApplicationContext ctx = new ResourceXmlApplicationContext(resource, Collections.EMPTY_LIST, null, Collections.EMPTY_LIST, false) {
protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader) {
reader.setValidating(false);
}
};
// Handle properties in configuration
PropertyPlaceholderConfigurer configurator =
new PropertyPlaceholderConfigurer();
//convert dictionary to properties. Is there a better way?
Properties props = new Properties();
Enumeration elements = properties.keys();
while (elements.hasMoreElements()) {
Object key = elements.nextElement();
props.put(key, properties.get(key));
}
configurator.setProperties(props);
configurator.setIgnoreUnresolvablePlaceholders(true);
ctx.addBeanFactoryPostProcessor(configurator);
ctx.refresh();
// Start the broker
BrokerService broker = ctx.getBean(BrokerService.class);
if (broker == null) {
throw new ConfigurationException(null, "Broker not defined");
}
//TODO deal with multiple brokers