private void setupAndRun(Properties jbNodeProperties, String[] modules) {
        logger.log(Level.INFO, "Setting up Spring contexts");

        ApplicationContext rootContext = new ClassPathXmlApplicationContext(new String[] {JBNODE_PROPERTIES_XML});

        PropertyPlaceholderConfigurer propertyPlaceholderConfigurer =
                (PropertyPlaceholderConfigurer)rootContext.getBean("jbNodePropertyPlaceholder");
        propertyPlaceholderConfigurer.setProperties(jbNodeProperties);

        ClassPathXmlApplicationContext mainContext = new ClassPathXmlApplicationContext(
                rootContext
        );

        mainContext.addBeanFactoryPostProcessor(propertyPlaceholderConfigurer);
        mainContext.setConfigLocation(JBNODE_XML);
        mainContext.refresh();

        jbNode = (JBNode)mainContext.getBean("jbNode");
        boolean hasErrors = false; 

        for(String module : modules) {
            logger.log(Level.INFO, "Discovering module '" + module + "'");

            ApplicationContext moduleContext = new ClassPathXmlApplicationContext(new String[] { module + ".xml"});

            for(String beanName : moduleContext.getBeanDefinitionNames()) {
                try {
                    Object bean = moduleContext.getBean(beanName);
                    try {
                        if(bean.getClass().getField(Constants.FIELD_JB_NODE_VERSION) != null) {
                            jbNode.configure(beanName, bean);
                        }
                    } catch (NoSuchFieldException e) {
                        
                    }
                } catch (JBNodeException e) {
                    logger.log(Level.SEVERE, "Can't configure bean '" + beanName + "' ", e);
                    hasErrors = true;
                    break;
                }
            }
        }

        if(!hasErrors) {
            try {
                logger.log(Level.INFO, "Starting jbNode...");
                jbNode.start();
            } catch (JBNodeException e) {
                logger.log(Level.SEVERE, "jbNode can't start", e);
            }
        } else {
            logger.log(Level.SEVERE, "Exceptions encountered while configuring jbNode service. Exiting.");
        }

    }